From dfa9e435af7477bddb147a8af3700143b27b5dc6 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Wed, 7 Nov 2018 10:44:22 -0800 Subject: Implemented Address --- packages/order-utils/test/abi_encoder_test.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'packages/order-utils') diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts index 292e615f3..7fb091019 100644 --- a/packages/order-utils/test/abi_encoder_test.ts +++ b/packages/order-utils/test/abi_encoder_test.ts @@ -309,9 +309,6 @@ namespace AbiEncoder { public abstract assignValue(value: any): void; public abstract getSignature(): string; - public abstract encodeToCalldata(calldata: Calldata): void; - - // abstract match(type: string): Bool; } export abstract class StaticDataType extends DataType { @@ -333,16 +330,13 @@ namespace AbiEncoder { } public assignValue(value: string) { - const hexValue = ethUtil.bufferToHex(new Buffer(value)); + const evmWordWidth = 32; + const hexValue = ethUtil.bufferToHex(ethUtil.setLengthLeft(ethUtil.toBuffer(value), evmWordWidth)); this.assignHexValue(hexValue); } public getSignature(): string { - throw 1; - } - - public encodeToCalldata(calldata: Calldata): void { - throw 2; + return `address`; } public static matchGrammar(type: string): boolean { @@ -634,8 +628,6 @@ namespace AbiEncoder { public getHexValue(): string { let offset = new BigNumber(0); if (this.memblock !== undefined) { - console.log('Abs Offset = ', JSON.stringify(this.destDataType.getAbsoluteOffset())); - console.log('Local Offset = ', JSON.stringify(this.destDataType.getOffset())); switch (this.memblock.getSection()) { case CalldataSection.PARAMS: offset = this.destDataType.getAbsoluteOffset(); @@ -786,6 +778,19 @@ describe.only('ABI Encoder', () => { }); }); + describe.only('Address', () => { + const testAddressDataItem = { name: 'testAddress', type: 'address' }; + it('Valid Address', async () => { + const addressDataType = new AbiEncoder.Address(testAddressDataItem); + addressDataType.assignValue('0xe41d2489571d322189246dafa5ebde1f4699f498'); + const expectedAbiEncodedAddress = '0x000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498'; + + console.log(addressDataType.getHexValue()); + console.log(expectedAbiEncodedAddress); + expect(addressDataType.getHexValue()).to.be.equal(expectedAbiEncodedAddress); + }); + }); + describe('String', () => { const testStringDataItem = { name: 'testString', type: 'string' }; it('Less than 32 bytes', async () => { -- cgit v1.2.3