aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-10 10:59:27 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commit41e01e98064b129f588d72ed25267f4865c58f5c (patch)
tree194e741b271d863d88d18c9b14471f336f43b633 /packages
parent0835cf0ea2bb3c2c18d2a5d44ec914e2945af1b0 (diff)
downloaddexon-0x-contracts-41e01e98064b129f588d72ed25267f4865c58f5c.tar
dexon-0x-contracts-41e01e98064b129f588d72ed25267f4865c58f5c.tar.gz
dexon-0x-contracts-41e01e98064b129f588d72ed25267f4865c58f5c.tar.bz2
dexon-0x-contracts-41e01e98064b129f588d72ed25267f4865c58f5c.tar.lz
dexon-0x-contracts-41e01e98064b129f588d72ed25267f4865c58f5c.tar.xz
dexon-0x-contracts-41e01e98064b129f588d72ed25267f4865c58f5c.tar.zst
dexon-0x-contracts-41e01e98064b129f588d72ed25267f4865c58f5c.zip
making progress on basic example
Diffstat (limited to 'packages')
-rw-r--r--packages/order-utils/test/abi/data_type.ts15
-rw-r--r--packages/order-utils/test/abi/evm_data_types.ts7
-rw-r--r--packages/order-utils/test/abi_encoder_test.ts10
3 files changed, 20 insertions, 12 deletions
diff --git a/packages/order-utils/test/abi/data_type.ts b/packages/order-utils/test/abi/data_type.ts
index 201eb89f9..c1e352508 100644
--- a/packages/order-utils/test/abi/data_type.ts
+++ b/packages/order-utils/test/abi/data_type.ts
@@ -95,15 +95,17 @@ export abstract class MemberDataType extends DataType {
private members: DataType[];
private isArray: boolean;
protected arrayLength: number | undefined;
+ protected arrayElementType: string | undefined;
- public constructor(dataItem: DataItem, isArray: boolean = false, arrayLength?: number) {
+ public constructor(dataItem: DataItem, isArray: boolean = false, arrayLength?: number, arrayElementType?: string) {
super(dataItem);
this.memberMap = {};
this.members = [];
this.isArray = isArray;
this.arrayLength = arrayLength;
+ this.arrayElementType = arrayElementType;
if (isArray && arrayLength !== undefined) {
[this.members, this.memberMap] = this.createMembersWithLength(dataItem, arrayLength);
} else if (!isArray) {
@@ -119,10 +121,10 @@ export abstract class MemberDataType extends DataType {
let members: DataType[] = [];
let memberMap: MemberMap = {};
- _.each(dataItem.components, (dataItem: DataItem) => {
+ _.each(dataItem.components, (memberItem: DataItem) => {
const childDataItem = {
- type: dataItem.type,
- name: `${dataItem.name}.${dataItem.name}`,
+ type: memberItem.type,
+ name: `${dataItem.name}.${memberItem.name}`,
} as DataItem;
const child = DataTypeFactory.create(childDataItem, this);
members.push(child);
@@ -133,12 +135,13 @@ 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);
_.each(range, (idx: number) => {
const childDataItem = {
- type: dataItem.type,
+ type: this.arrayElementType,
name: `${dataItem.name}[${idx.toString(10)}]`,
} as DataItem;
const components = dataItem.components;
@@ -164,7 +167,7 @@ export abstract class MemberDataType extends DataType {
}
let members = this.members;
- if (this.arrayLength === undefined) {
+ if (this.isArray && this.arrayLength === undefined) {
[members,] = this.createMembersWithLength(this.getDataItem(), value.length);
}
diff --git a/packages/order-utils/test/abi/evm_data_types.ts b/packages/order-utils/test/abi/evm_data_types.ts
index 4dffedb8d..1bd4f0d51 100644
--- a/packages/order-utils/test/abi/evm_data_types.ts
+++ b/packages/order-utils/test/abi/evm_data_types.ts
@@ -347,9 +347,10 @@ export class SolArray extends MemberDataType {
}
const isArray = true;
+ const arrayElementType = matches[1];
const arrayLength = (matches[2] === '') ? undefined : parseInt(matches[2], 10);
- super(dataItem, isArray, arrayLength);
- this.elementType = matches[1];
+ super(dataItem, isArray, arrayLength, arrayElementType);
+ this.elementType = arrayElementType;
this.arraySignature = this.computeSignature();
}
@@ -388,7 +389,7 @@ export class Method extends MemberDataType {
public selector: string;
constructor(abi: MethodAbi) {
- super({ type: 'method', name: abi.name });
+ super({ type: 'method', name: abi.name, components: abi.inputs });
this.methodSignature = this.computeSignature();
this.selector = this.methodSelector = this.computeSelector();
diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts
index d75c9dbf1..6655af1ff 100644
--- a/packages/order-utils/test/abi_encoder_test.ts
+++ b/packages/order-utils/test/abi_encoder_test.ts
@@ -18,13 +18,15 @@ import * as AbiEncoder from './abi/abi_encoder';
import * as AbiSamples from './abi_samples';
+AbiEncoder.DataTypeFactory.setImpl(new AbiEncoder.EvmDataTypeFactoryImpl());
+
chaiSetup.configure();
const expect = chai.expect;
describe.only('ABI Encoder', () => {
describe.only('ABI Tests at Method Level', () => {
- it('Crazy ABI', async () => {
+ it.skip('Crazy ABI', async () => {
const method = new AbiEncoder.Method(AbiSamples.crazyAbi);
console.log(method.getSignature());
@@ -89,8 +91,9 @@ describe.only('ABI Encoder', () => {
expect(calldata).to.be.equal(expectedCalldata);
});
- it('Crazy ABI #1', async () => {
+ it.skip('Crazy ABI #1', async () => {
const method = new AbiEncoder.Method(AbiSamples.crazyAbi1);
+
const args = [
new BigNumber(256745454),
new BigNumber(-256745454),
@@ -115,6 +118,7 @@ describe.only('ABI Encoder', () => {
it('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']];
const calldata = method.encode(args);
console.log(calldata);
@@ -325,7 +329,7 @@ describe.only('ABI Encoder', () => {
expect(calldata).to.be.equal(expectedCalldata);
});
- it('Yessir', async () => {
+ it.only('Yessir', async () => {
const method = new AbiEncoder.Method(AbiSamples.simpleAbi);
const calldata = method.encode([new BigNumber(5), 'five']);
console.log(calldata);