diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-20 03:18:34 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:10 +0800 |
commit | a2ad15be0dc500fa196021a5b32e80af8500043c (patch) | |
tree | 3f7dcd493c3a92e39b8583f67c6b79a02f579ce2 /packages/utils/test | |
parent | a630312074758b31951c194533dcae596424592d (diff) | |
download | dexon-sol-tools-a2ad15be0dc500fa196021a5b32e80af8500043c.tar dexon-sol-tools-a2ad15be0dc500fa196021a5b32e80af8500043c.tar.gz dexon-sol-tools-a2ad15be0dc500fa196021a5b32e80af8500043c.tar.bz2 dexon-sol-tools-a2ad15be0dc500fa196021a5b32e80af8500043c.tar.lz dexon-sol-tools-a2ad15be0dc500fa196021a5b32e80af8500043c.tar.xz dexon-sol-tools-a2ad15be0dc500fa196021a5b32e80af8500043c.tar.zst dexon-sol-tools-a2ad15be0dc500fa196021a5b32e80af8500043c.zip |
Tests for Address
Diffstat (limited to 'packages/utils/test')
-rw-r--r-- | packages/utils/test/abi_encoder_test.ts | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/packages/utils/test/abi_encoder_test.ts b/packages/utils/test/abi_encoder_test.ts index cf1f0327a..5b341545e 100644 --- a/packages/utils/test/abi_encoder_test.ts +++ b/packages/utils/test/abi_encoder_test.ts @@ -725,7 +725,7 @@ describe.only('ABI Encoder', () => { }); }); - describe('Array', () => { + describe.only('Array', () => { it('Fixed size; Static elements', async () => { // Create DataType object const testDataItem = { name: 'testArray', type: 'int[2]' }; @@ -793,6 +793,9 @@ describe.only('ABI Encoder', () => { const argsAsJson = JSON.stringify(args); expect(decodedArgsAsJson).to.be.equal(argsAsJson); }); + + // @TODO: Add test that fails if we pass in the wrong number of elements + // @TODO: Add test that fails if we pass in an element of incorrecrt type }); describe.only('Tuple', () => { @@ -849,22 +852,51 @@ describe.only('ABI Encoder', () => { const argsAsJson = JSON.stringify(args); expect(decodedArgsAsJson).to.be.equal(argsAsJson); }); + + // @TODO: Add test that fails if we pass in the wrong number of elements + // @TODO: Add test that fails if we pass in arguments in wrong order }); - /* - describe('Address', () => { - const testAddressDataItem = { name: 'testAddress', type: 'address' }; + describe.only('Address', () => { it('Valid Address', async () => { - const addressDataType = new AbiEncoder.Address(testAddressDataItem); - addressDataType.assignValue('0xe41d2489571d322189246dafa5ebde1f4699f498'); - const expectedAbiEncodedAddress = '0x000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498'; + // Create DataType object + const testDataItem = { name: 'Address', type: 'address' }; + const dataType = new AbiEncoder.Address(testDataItem); + // Construct args to be encoded + const args = '0xe41d2489571d322189246dafa5ebde1f4699f498'; + // Encode Args and validate result + const encodedArgs = dataType.encode(args); + const expectedEncodedArgs = '0x000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498'; + expect(encodedArgs).to.be.equal(expectedEncodedArgs); + // Decode Encoded Args and validate result + const decodedArgs = dataType.decode(encodedArgs); + const decodedArgsAsJson = JSON.stringify(decodedArgs); + const argsAsJson = JSON.stringify(args); + expect(decodedArgsAsJson).to.be.equal(argsAsJson); + }); - console.log(addressDataType.getHexValue()); - console.log(expectedAbiEncodedAddress); - expect(addressDataType.getHexValue()).to.be.equal(expectedAbiEncodedAddress); + it('Invalid Address - input is not valid hex', async () => { + // Create DataType object + const testDataItem = { name: 'Address', type: 'address' }; + const dataType = new AbiEncoder.Address(testDataItem); + // Construct args to be encoded + const args = 'e4'; + // Encode Args and validate result + expect(() => { dataType.encode(args) }).to.throw(AbiEncoder.Address.ERROR_MESSAGE_ADDRESS_MUST_START_WITH_0X); + }); + + it('Invalid Address - input is not 20 bytes', async () => { + // Create DataType object + const testDataItem = { name: 'Address', type: 'address' }; + const dataType = new AbiEncoder.Address(testDataItem); + // Construct args to be encoded + const args = '0xe4'; + // Encode Args and validate result + expect(() => { dataType.encode(args) }).to.throw(AbiEncoder.Address.ERROR_MESSAGE_ADDRESS_MUST_BE_20_BYTES); }); }); + /* describe('Bool', () => { const testBoolDataItem = { name: 'testBool', type: 'bool' }; it('True', async () => { |