aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/order-utils/test/abi_encoder_test.ts57
-rw-r--r--packages/order-utils/test/abi_samples.ts50
2 files changed, 105 insertions, 2 deletions
diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts
index 661fb62a6..78e28015d 100644
--- a/packages/order-utils/test/abi_encoder_test.ts
+++ b/packages/order-utils/test/abi_encoder_test.ts
@@ -41,7 +41,7 @@ describe.only('ABI Encoder', () => {
console.log(optimizedCalldata);
});
- it.only('Optimizer #2', async () => {
+ it('Optimizer #2', async () => {
const method = new AbiEncoder.Method(AbiSamples.optimizerAbi2);
const stringArray = [
"Test String",
@@ -60,8 +60,61 @@ describe.only('ABI Encoder', () => {
console.log(`OPTIMIZED CALLDATA == '${optimizedCalldata}'`);
const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgsJson = JSON.stringify(decodedArgs);
+ const argsJson = JSON.stringify(args);
console.log(JSON.stringify(decodedArgs));
- //expect(decodedArgs).to.be.equal(args);
+ expect(decodedArgsJson).to.be.equal(argsJson);
+ });
+
+
+ it('Optimizer #3 (tuple should point to array)', async () => {
+ const method = new AbiEncoder.Method(AbiSamples.optimizerAbi3);
+ const uint8Array = [
+ new BigNumber(100),
+ new BigNumber(150),
+ new BigNumber(200),
+ new BigNumber(225),
+ ];
+ const uintTupleArray = [[uint8Array[0]], [uint8Array[1]], [uint8Array[2]], [uint8Array[3]]];
+ const args = [uint8Array, uintTupleArray];
+
+
+ const TEST = method.encode(args, new Calldata(), true, true);
+ console.log('*'.repeat(50), ' ENCODED DATA ', TEST);
+
+ const optimizedCalldata = method.encode(args, new Calldata(), false, true);
+
+ console.log(`OPTIMIZED CALLDATA == '${optimizedCalldata}'`);
+ const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgsJson = JSON.stringify(decodedArgs);
+ const argsJson = JSON.stringify(args);
+ console.log(JSON.stringify(decodedArgs));
+ expect(decodedArgsJson).to.be.equal(argsJson);
+ });
+
+ it.only('Optimizer #4 (Expect no optimization)', async () => {
+ const method = new AbiEncoder.Method(AbiSamples.optimizerAbi4);
+ const uint8Array = [
+ new BigNumber(100),
+ new BigNumber(150),
+ new BigNumber(200),
+ new BigNumber(225),
+ ];
+ const uintTupleArray = [[uint8Array[0]], [uint8Array[1]], [uint8Array[2]], [uint8Array[3]]];
+ const args = [uint8Array, uintTupleArray];
+
+
+ const TEST = method.encode(args, new Calldata(), true, true);
+ console.log('*'.repeat(50), ' ENCODED DATA ', TEST);
+
+ const optimizedCalldata = method.encode(args, new Calldata(), false, true);
+
+ console.log(`OPTIMIZED CALLDATA == '${optimizedCalldata}'`);
+ const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgsJson = JSON.stringify(decodedArgs);
+ const argsJson = JSON.stringify(args);
+ console.log(JSON.stringify(decodedArgs));
+ expect(decodedArgsJson).to.be.equal(argsJson);
});
it('Crazy ABI', async () => {
diff --git a/packages/order-utils/test/abi_samples.ts b/packages/order-utils/test/abi_samples.ts
index fa20c38f0..5e8268f1a 100644
--- a/packages/order-utils/test/abi_samples.ts
+++ b/packages/order-utils/test/abi_samples.ts
@@ -53,6 +53,56 @@ export const optimizerAbi2 = {
type: 'function',
} as MethodAbi;
+export const optimizerAbi3 = {
+ constant: false,
+ inputs: [
+ {
+ name: 'uint8Array',
+ type: 'uint8[]',
+ },
+ {
+ components: [
+ {
+ name: 'uint',
+ type: 'uint',
+ },
+ ],
+ name: 'uintTuple',
+ type: 'tuple[]',
+ },
+ ],
+ name: 'simpleFunction',
+ outputs: [],
+ payable: false,
+ stateMutability: 'nonpayable',
+ type: 'function',
+} as MethodAbi;
+
+export const optimizerAbi4 = {
+ constant: false,
+ inputs: [
+ {
+ name: 'uint8Array',
+ type: 'uint8[4]',
+ },
+ {
+ components: [
+ {
+ name: 'uint',
+ type: 'uint',
+ },
+ ],
+ name: 'uintTuple',
+ type: 'tuple[]',
+ },
+ ],
+ name: 'simpleFunction',
+ outputs: [],
+ payable: false,
+ stateMutability: 'nonpayable',
+ type: 'function',
+} as MethodAbi;
+
export const typesWithDefaultWidthsAbi = {
constant: false,
inputs: [