aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/order-utils')
-rw-r--r--packages/order-utils/test/abi/calldata.ts6
-rw-r--r--packages/order-utils/test/abi_encoder_test.ts25
-rw-r--r--packages/order-utils/test/abi_samples.ts19
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: [