diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-10 14:24:24 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:10 +0800 |
commit | 59206c387e702492d22e975acf806ebe7de36bfd (patch) | |
tree | b6ac130c7f197c28bb1224fd25640b09ad92cbb2 /packages | |
parent | 20f1526c7d0e1edb4a1de8e8a26811ae81b609dc (diff) | |
download | dexon-0x-contracts-59206c387e702492d22e975acf806ebe7de36bfd.tar dexon-0x-contracts-59206c387e702492d22e975acf806ebe7de36bfd.tar.gz dexon-0x-contracts-59206c387e702492d22e975acf806ebe7de36bfd.tar.bz2 dexon-0x-contracts-59206c387e702492d22e975acf806ebe7de36bfd.tar.lz dexon-0x-contracts-59206c387e702492d22e975acf806ebe7de36bfd.tar.xz dexon-0x-contracts-59206c387e702492d22e975acf806ebe7de36bfd.tar.zst dexon-0x-contracts-59206c387e702492d22e975acf806ebe7de36bfd.zip |
Works for types with default widths
Diffstat (limited to 'packages')
-rw-r--r-- | packages/order-utils/test/abi/calldata.ts | 24 | ||||
-rw-r--r-- | packages/order-utils/test/abi/data_type.ts | 9 | ||||
-rw-r--r-- | packages/order-utils/test/abi_encoder_test.ts | 6 |
3 files changed, 19 insertions, 20 deletions
diff --git a/packages/order-utils/test/abi/calldata.ts b/packages/order-utils/test/abi/calldata.ts index c1630c34a..dc67a731e 100644 --- a/packages/order-utils/test/abi/calldata.ts +++ b/packages/order-utils/test/abi/calldata.ts @@ -91,15 +91,10 @@ export class DependentCalldataBlock extends CalldataBlock { public toBuffer(): Buffer { const dependencyOffset = this.dependency.getOffsetInBytes(); - console.log("Dependency Offset - ", dependencyOffset); const parentOffset = this.parent.getOffsetInBytes(); - console.log("Parent Offset - ", parentOffset); const parentHeaderSize = this.parent.getHeaderSizeInBytes(); - console.log("Parent Header size - ", parentHeaderSize); const pointer: number = dependencyOffset - (parentOffset + parentHeaderSize); - console.log("DAT PTR = ", pointer); const pointerBuf = ethUtil.toBuffer(`0x${pointer.toString(16)}`); - console.log("Chye - ", pointerBuf); const evmWordWidthInBytes = 32; const pointerBufPadded = ethUtil.setLengthLeft(pointerBuf, evmWordWidthInBytes); return pointerBufPadded; @@ -114,11 +109,13 @@ export class MemberCalldataBlock extends CalldataBlock { private static DEPENDENT_PAYLOAD_SIZE_IN_BYTES = 32; private header: Buffer | undefined; private members: CalldataBlock[]; + private contiguous: boolean; - constructor(name: string, signature: string, /*offsetInBytes: number,*/ relocatable: boolean) { + constructor(name: string, signature: string, /*offsetInBytes: number,*/ relocatable: boolean, contiguous: boolean) { super(name, signature, /*offsetInBytes,*/ 0, 0, relocatable); this.members = []; this.header = undefined; + this.contiguous = contiguous; } public setMembers(members: CalldataBlock[]) { @@ -130,6 +127,10 @@ export class MemberCalldataBlock extends CalldataBlock { this.setBodySize(0); } + public isContiguous(): boolean { + return true; + } + public setHeader(header: Buffer) { this.setHeaderSize(header.byteLength); this.header = header; @@ -150,6 +151,9 @@ class Queue<T> { push(val: T) { this.store.push(val); } + pushFront(val: T) { + this.store.unshift(val); + } pop(): T | undefined { return this.store.shift(); } @@ -186,8 +190,8 @@ export class Calldata { console.log(block.getDependency()); blockQueue.push(block.getDependency()); } else if (block instanceof MemberCalldataBlock) { - _.each(block.getMembers(), (member: CalldataBlock) => { - blockQueue.push(member); + _.eachRight(block.getMembers(), (member: CalldataBlock) => { + blockQueue.pushFront(member); }); } } @@ -203,8 +207,8 @@ export class Calldata { if (block instanceof DependentCalldataBlock) { blockQueue.push(block.getDependency()); } else if (block instanceof MemberCalldataBlock) { - _.each(block.getMembers(), (member: CalldataBlock) => { - blockQueue.push(member); + _.eachRight(block.getMembers(), (member: CalldataBlock) => { + blockQueue.pushFront(member); }); } } diff --git a/packages/order-utils/test/abi/data_type.ts b/packages/order-utils/test/abi/data_type.ts index 72d270bf1..0783b9c56 100644 --- a/packages/order-utils/test/abi/data_type.ts +++ b/packages/order-utils/test/abi/data_type.ts @@ -32,7 +32,6 @@ export abstract class PayloadDataType extends DataType { } public generateCalldataBlock(value: any, parentBlock?: CalldataBlock): PayloadCalldataBlock { - //console.log(); const encodedValue = this.encodeValue(value); const name = this.getDataItem().name; const signature = this.getSignature(); @@ -101,9 +100,6 @@ export abstract class MemberDataType extends DataType { public constructor(dataItem: DataItem, isArray: boolean = false, arrayLength?: number, arrayElementType?: string) { super(dataItem); - - console.log('*'.repeat(40), arrayLength); - this.memberMap = {}; this.members = []; this.isArray = isArray; @@ -138,7 +134,6 @@ export abstract class MemberDataType extends DataType { } private createMembersWithLength(dataItem: DataItem, length: number): [DataType[], MemberMap] { - console.log(dataItem); let members: DataType[] = []; let memberMap: MemberMap = {}; const range = _.range(length); @@ -169,7 +164,7 @@ export abstract class MemberDataType extends DataType { ); } - const methodBlock: MemberCalldataBlock = new MemberCalldataBlock(this.getDataItem().name, this.getSignature(), false); + const methodBlock: MemberCalldataBlock = new MemberCalldataBlock(this.getDataItem().name, this.getSignature(), this.isStatic(), false); let members = this.members; if (this.isArray && this.arrayLength === undefined) { @@ -190,7 +185,7 @@ export abstract class MemberDataType extends DataType { } protected generateCalldataBlockFromObject(obj: object): MemberCalldataBlock { - const methodBlock: MemberCalldataBlock = new MemberCalldataBlock(this.getDataItem().name, this.getSignature(), false); + const methodBlock: MemberCalldataBlock = new MemberCalldataBlock(this.getDataItem().name, this.getSignature(), this.isStatic(), false); const memberBlocks: CalldataBlock[] = []; let childMap = _.cloneDeep(this.memberMap); _.forOwn(obj, (value: any, key: string) => { diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts index 4c571434e..404f160fd 100644 --- a/packages/order-utils/test/abi_encoder_test.ts +++ b/packages/order-utils/test/abi_encoder_test.ts @@ -116,7 +116,7 @@ describe.only('ABI Encoder', () => { }); - it('Types with default widths', async () => { + it.only('Types with default widths', async () => { const method = new AbiEncoder.Method(AbiSamples.typesWithDefaultWidthsAbi); console.log(method); const args = [new BigNumber(1), new BigNumber(-1), '0x56', [new BigNumber(1)], [new BigNumber(-1)], ['0x56']]; @@ -201,7 +201,7 @@ describe.only('ABI Encoder', () => { expect(calldata).to.be.equal(expectedCalldata); }); - it('Multidimensional Arrays / Static Members', async () => { + it.only('Multidimensional Arrays / Static Members', async () => { const method = new AbiEncoder.Method(AbiSamples.multiDimensionalArraysStaticTypeAbi); // Eight 3-dimensional arrays of uint8[2][2][2] @@ -259,7 +259,7 @@ describe.only('ABI Encoder', () => { expect(calldata).to.be.equal(expectedCalldata); }); - it.only('Fixed Lenfgth Array / Dynamic Members', async () => { + it('Fixed Lenfgth Array / Dynamic Members', async () => { const method = new AbiEncoder.Method(AbiSamples.staticArrayDynamicMembersAbi); const args = [["Brave", "New", "World"]]; const calldata = method.encode(args); |