aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-14 09:40:14 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commit93e967c3b356f0081254946bbf8d6875fc791a09 (patch)
treea74098394fdcd19d2da57a1730004b22b9486255
parentb71577cc52d7f933ee7e5dc50e5b61457f04e3f4 (diff)
downloaddexon-sol-tools-93e967c3b356f0081254946bbf8d6875fc791a09.tar
dexon-sol-tools-93e967c3b356f0081254946bbf8d6875fc791a09.tar.gz
dexon-sol-tools-93e967c3b356f0081254946bbf8d6875fc791a09.tar.bz2
dexon-sol-tools-93e967c3b356f0081254946bbf8d6875fc791a09.tar.lz
dexon-sol-tools-93e967c3b356f0081254946bbf8d6875fc791a09.tar.xz
dexon-sol-tools-93e967c3b356f0081254946bbf8d6875fc791a09.tar.zst
dexon-sol-tools-93e967c3b356f0081254946bbf8d6875fc791a09.zip
Some tests
-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: [