diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-14 08:17:24 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:10 +0800 |
commit | 27cb966991c9408025106624f36927548b9e873c (patch) | |
tree | 71431e1f56572bcc160ed6397e58af5de489b036 /packages/order-utils/test | |
parent | 457cb1dc843511d6e987b0ffce0f985d4e97c968 (diff) | |
download | dexon-sol-tools-27cb966991c9408025106624f36927548b9e873c.tar dexon-sol-tools-27cb966991c9408025106624f36927548b9e873c.tar.gz dexon-sol-tools-27cb966991c9408025106624f36927548b9e873c.tar.bz2 dexon-sol-tools-27cb966991c9408025106624f36927548b9e873c.tar.lz dexon-sol-tools-27cb966991c9408025106624f36927548b9e873c.tar.xz dexon-sol-tools-27cb966991c9408025106624f36927548b9e873c.tar.zst dexon-sol-tools-27cb966991c9408025106624f36927548b9e873c.zip |
Alias now points to dependency, not pointer
Diffstat (limited to 'packages/order-utils/test')
-rw-r--r-- | packages/order-utils/test/abi/calldata.ts | 6 | ||||
-rw-r--r-- | packages/order-utils/test/abi_encoder_test.ts | 25 | ||||
-rw-r--r-- | packages/order-utils/test/abi_samples.ts | 19 |
3 files changed, 46 insertions, 4 deletions
diff --git a/packages/order-utils/test/abi/calldata.ts b/packages/order-utils/test/abi/calldata.ts index ab42b7d73..04bea9628 100644 --- a/packages/order-utils/test/abi/calldata.ts +++ b/packages/order-utils/test/abi/calldata.ts @@ -403,7 +403,7 @@ export class Calldata { // Optimize const lastSubtree = subtrees[subtrees.length - 1]; for (let i = 0; i < subtrees.length - 1; ++i) { - subtrees[i].setAlias(lastSubtree); + subtrees[i].setAlias(lastSubtree.getDependency()); } }); } @@ -413,6 +413,8 @@ export class Calldata { throw new Error('expected root'); } + if (optimize) this.optimize(); + const offsetQueue = this.createQueue(this.root); let block: CalldataBlock | undefined; let offset = 0; @@ -421,8 +423,6 @@ export class Calldata { offset += block.getSizeInBytes(); } - if (optimize) this.optimize(); - const hexValue = annotate ? this.generateAnnotatedHexString() : this.generateCondensedHexString(); return hexValue; } diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts index 5ef4203b7..661fb62a6 100644 --- a/packages/order-utils/test/abi_encoder_test.ts +++ b/packages/order-utils/test/abi_encoder_test.ts @@ -27,7 +27,7 @@ const expect = chai.expect; describe.only('ABI Encoder', () => { describe.only('ABI Tests at Method Level', () => { - it.only('Optimizer', async () => { + it('Optimizer #1', async () => { const method = new AbiEncoder.Method(AbiSamples.stringAbi); const strings = [ "Test String", @@ -41,6 +41,29 @@ describe.only('ABI Encoder', () => { console.log(optimizedCalldata); }); + it.only('Optimizer #2', async () => { + const method = new AbiEncoder.Method(AbiSamples.optimizerAbi2); + const stringArray = [ + "Test String", + "Test String", + "Test String", + "Test String", + ]; + const string = 'Test String'; + const args = [stringArray, string]; + + + const TEST = method.encode(args, new Calldata(), true, true); + console.log(TEST); + + const optimizedCalldata = method.encode(args, new Calldata(), false, true); + + console.log(`OPTIMIZED CALLDATA == '${optimizedCalldata}'`); + const decodedArgs = method.decode(optimizedCalldata); + console.log(JSON.stringify(decodedArgs)); + //expect(decodedArgs).to.be.equal(args); + }); + it('Crazy ABI', async () => { const method = new AbiEncoder.Method(AbiSamples.crazyAbi); console.log(method.getSignature()); diff --git a/packages/order-utils/test/abi_samples.ts b/packages/order-utils/test/abi_samples.ts index 3f7b1a927..fa20c38f0 100644 --- a/packages/order-utils/test/abi_samples.ts +++ b/packages/order-utils/test/abi_samples.ts @@ -34,6 +34,25 @@ export const stringAbi = { type: 'function', } as MethodAbi; +export const optimizerAbi2 = { + constant: false, + inputs: [ + { + name: 'stringArray', + type: 'string[]', + }, + { + name: 'string', + type: 'string', + }, + ], + name: 'simpleFunction', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', +} as MethodAbi; + export const typesWithDefaultWidthsAbi = { constant: false, inputs: [ |