aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-15 06:27:33 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commit3ae434c31e720cb1caf65d776b75524dab388a2f (patch)
treebea817eed0b73d5f6100795deed4d768180d9d5c
parent063871e549483ba36e5ee2317249eb6dccda24a4 (diff)
downloaddexon-0x-contracts-3ae434c31e720cb1caf65d776b75524dab388a2f.tar
dexon-0x-contracts-3ae434c31e720cb1caf65d776b75524dab388a2f.tar.gz
dexon-0x-contracts-3ae434c31e720cb1caf65d776b75524dab388a2f.tar.bz2
dexon-0x-contracts-3ae434c31e720cb1caf65d776b75524dab388a2f.tar.lz
dexon-0x-contracts-3ae434c31e720cb1caf65d776b75524dab388a2f.tar.xz
dexon-0x-contracts-3ae434c31e720cb1caf65d776b75524dab388a2f.tar.zst
dexon-0x-contracts-3ae434c31e720cb1caf65d776b75524dab388a2f.zip
Adding optimizer tests
-rw-r--r--packages/order-utils/test/abi_encoder_test.ts36
1 files changed, 26 insertions, 10 deletions
diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts
index 52b6bc067..8ae23a222 100644
--- a/packages/order-utils/test/abi_encoder_test.ts
+++ b/packages/order-utils/test/abi_encoder_test.ts
@@ -25,6 +25,10 @@ chaiSetup.configure();
const expect = chai.expect;
describe.only('ABI Encoder', () => {
+ describe.only('Optimizer', () => {
+
+ });
+
describe.only('ABI Tests at Method Level', () => {
it('Should reuse duplicated strings in string array', async () => {
@@ -37,33 +41,45 @@ describe.only('ABI Encoder', () => {
];
const args = [strings];
- const optimizedCalldata = method.encode(args, { optimize: true, annotate: true });
- console.log(optimizedCalldata);
+ // Verify optimized calldata is expected
+ const optimizedCalldata = method.encode(args, { optimize: true });
+ const expectedOptimizedCalldata = '0x13e751a900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000b5465737420537472696e67000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d5465737420537472696e67203200000000000000000000000000000000000000';
+ expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
+
+ // Verify args decode properly
+ const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgsJson = JSON.stringify(decodedArgs);
+ const argsJson = JSON.stringify(args);
+ expect(decodedArgsJson).to.be.equal(argsJson);
+
+ console.log('*'.repeat(100), '\n', method.encode(args, { optimize: true, annotate: true }), '\n', '*'.repeat(100));
+ console.log('*'.repeat(100), '\n', method.encode(args, { optimize: true }), '\n', '*'.repeat(100));
});
- it('Optimizer #2', async () => {
+ it.only('Should point array elements to a duplicated value from another parameter', async () => {
const method = new AbiEncoder.Method(AbiSamples.optimizerAbi2);
const stringArray = [
"Test String",
"Test String",
"Test String",
- "Test String",
+ "Test String 2",
];
const string = 'Test String';
const args = [stringArray, string];
-
- const TEST = method.encode(args, { optimize: true, annotate: true });
- console.log(TEST);
-
+ // Verify optimized calldata is expected
const optimizedCalldata = method.encode(args, { optimize: true });
+ const expectedOptimizedCalldata = '0xe0e0d34900000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000d5465737420537472696e67203200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b5465737420537472696e67000000000000000000000000000000000000000000';
+ expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
- console.log(`OPTIMIZED CALLDATA == '${optimizedCalldata}'`);
+ // Verify args decode properly
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);
+
+ console.log('*'.repeat(100), '\n', method.encode(args, { optimize: true, annotate: true }), '\n', '*'.repeat(100));
+ console.log('*'.repeat(100), '\n', method.encode(args, { optimize: true }), '\n', '*'.repeat(100));
});