aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/test
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-16 06:33:40 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commit8a8b904a292063d1adb3df0a84023610a3985f7f (patch)
treecfb0772901ec1965e2a68fd728b639ff592edf75 /packages/utils/test
parentebd4dbc6c6ebdf776ba1582367d3eda32717ba65 (diff)
downloaddexon-sol-tools-8a8b904a292063d1adb3df0a84023610a3985f7f.tar
dexon-sol-tools-8a8b904a292063d1adb3df0a84023610a3985f7f.tar.gz
dexon-sol-tools-8a8b904a292063d1adb3df0a84023610a3985f7f.tar.bz2
dexon-sol-tools-8a8b904a292063d1adb3df0a84023610a3985f7f.tar.lz
dexon-sol-tools-8a8b904a292063d1adb3df0a84023610a3985f7f.tar.xz
dexon-sol-tools-8a8b904a292063d1adb3df0a84023610a3985f7f.tar.zst
dexon-sol-tools-8a8b904a292063d1adb3df0a84023610a3985f7f.zip
Use new ABI Encoder for contracts
Diffstat (limited to 'packages/utils/test')
-rw-r--r--packages/utils/test/abi_encoder_test.ts29
-rw-r--r--packages/utils/test/abi_samples.ts34
2 files changed, 63 insertions, 0 deletions
diff --git a/packages/utils/test/abi_encoder_test.ts b/packages/utils/test/abi_encoder_test.ts
index 8d78b61b5..8add41af6 100644
--- a/packages/utils/test/abi_encoder_test.ts
+++ b/packages/utils/test/abi_encoder_test.ts
@@ -15,6 +15,35 @@ describe.only('ABI Encoder', () => {
describe.only('ABI Tests at Method Level', () => {
+ it.only('Should reuse duplicated strings in string array', async () => {
+ const method = new AbiEncoder.Method(AbiSamples.GAbi);
+
+ const args = [
+ {
+ a: new BigNumber(5),
+ e: '0x616161',
+ b: 'aaa',
+ f: '0xe41d2489571d322189246dafa5ebde1f4699f498'
+ }
+ ]
+
+ // 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(method.getSignature());
+ 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('Should reuse duplicated strings in string array', async () => {
const method = new AbiEncoder.Method(AbiSamples.stringAbi);
const strings = [
diff --git a/packages/utils/test/abi_samples.ts b/packages/utils/test/abi_samples.ts
index 5e8268f1a..aa38711cd 100644
--- a/packages/utils/test/abi_samples.ts
+++ b/packages/utils/test/abi_samples.ts
@@ -34,6 +34,40 @@ export const stringAbi = {
type: 'function',
} as MethodAbi;
+
+export const GAbi = {
+ constant: false,
+ inputs: [
+ {
+ components: [{
+ name: 'a',
+ type: 'uint256',
+ },
+ {
+ name: 'b',
+ type: 'string',
+ },
+ {
+ name: 'e',
+ type: 'bytes',
+ },
+ {
+ name: 'f',
+ type: 'address',
+ }],
+
+ name: 'f',
+ type: 'tuple',
+
+ }
+ ],
+ name: 'simpleFunction',
+ outputs: [],
+ payable: false,
+ stateMutability: 'nonpayable',
+ type: 'function',
+} as MethodAbi;
+
export const optimizerAbi2 = {
constant: false,
inputs: [