aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-09 03:33:51 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commit687e6ccdd37da7c35a3fafac43f0fdff03351c0c (patch)
tree4f3fb1332e0d26a2c44ab6e60d2a7d1f4666af88
parent3bc45395cc0e1c5c483e7319967b6308122123bf (diff)
downloaddexon-sol-tools-687e6ccdd37da7c35a3fafac43f0fdff03351c0c.tar
dexon-sol-tools-687e6ccdd37da7c35a3fafac43f0fdff03351c0c.tar.gz
dexon-sol-tools-687e6ccdd37da7c35a3fafac43f0fdff03351c0c.tar.bz2
dexon-sol-tools-687e6ccdd37da7c35a3fafac43f0fdff03351c0c.tar.lz
dexon-sol-tools-687e6ccdd37da7c35a3fafac43f0fdff03351c0c.tar.xz
dexon-sol-tools-687e6ccdd37da7c35a3fafac43f0fdff03351c0c.tar.zst
dexon-sol-tools-687e6ccdd37da7c35a3fafac43f0fdff03351c0c.zip
Got the crazy ABI working
-rw-r--r--packages/order-utils/test/abi_encoder.ts44
-rw-r--r--packages/order-utils/test/abi_encoder_test.ts4
2 files changed, 39 insertions, 9 deletions
diff --git a/packages/order-utils/test/abi_encoder.ts b/packages/order-utils/test/abi_encoder.ts
index 853aac627..ae573b39f 100644
--- a/packages/order-utils/test/abi_encoder.ts
+++ b/packages/order-utils/test/abi_encoder.ts
@@ -89,6 +89,10 @@ class Memblock {
public getSection(): CalldataSection {
return this.location.calldataSection;
}
+
+ public getName(): string {
+ return this.dataType.getDataItem().name;
+ }
}
interface BindList {
@@ -120,13 +124,18 @@ export class Calldata {
throw `Rebind on ${dataType.getId()}`;
}
const memblock = new Memblock(dataType);
+
+ this.params.push(memblock);
+ memblock.assignLocation(section, new BigNumber(0), this.currentParamOffset);
+
+ console.log(`Binding ${dataType.getDataItem().name} to PARAMS at ${this.currentParamOffset}`);
+ this.currentParamOffset = this.currentParamOffset.plus(memblock.getSize());
+ console.log("CURRENT PARAM OFFSET -------- 0x", this.currentParamOffset.toString(16));
+
+ /*
switch (section) {
case CalldataSection.PARAMS:
- this.params.push(memblock);
- memblock.assignLocation(section, new BigNumber(0), this.currentParamOffset);
-
- console.log(`Binding ${dataType.getDataItem().name} to PARAMS at ${this.currentParamOffset}`);
- this.currentParamOffset = this.currentParamOffset.plus(memblock.getSize());
+ ;
break;
case CalldataSection.DATA:
@@ -143,7 +152,7 @@ export class Calldata {
default:
throw `Unrecognized calldata section: ${section}`;
- }
+ }*/
this.bindList[dataType.getId()] = memblock;
dataType.rbind(memblock);
@@ -160,6 +169,26 @@ export class Calldata {
return hexValue;
}
+
+ public printAnnotated() {
+ let hexValue = `${this.selector}`;
+ console.log(hexValue);
+ let offset = new BigNumber(0);
+ _.each(this.params, (memblock: Memblock) => {
+ const offsetStr = `0x${offset.toString(16)}`;
+ const hexValue = memblock.get();
+ const annotation = memblock.getName();
+
+ console.log(`${offsetStr} ${hexValue} ${annotation}`);
+ });
+ _.each(this.data, (memblock: Memblock) => {
+ const offsetStr = `0x${offset.toString(16)}`;
+ const hexValue = memblock.get();
+ const annotation = memblock.getName();
+
+ console.log(`${offsetStr} ${hexValue} ${annotation}`);
+ });
+ }
}
export abstract class DataType {
@@ -793,7 +822,7 @@ export class Tuple extends DynamicDataType {
name: `${this.getDataItem().name}.${dataItem.name}`,
} as DataItem;
const child = DataTypeFactory.create(childDataItem, this);
- this.childMap[dataItem.name] = this.children.length;
+ this.childMap[dataItem.name] = this.members.length;
if (child instanceof Pointer) {
this.children.push(child.getChildren()[0]);
@@ -1065,6 +1094,7 @@ export class Method extends DataType {
public encode(args: any[]): string {
this.assignValue(args);
const calldata = new Calldata(this.selector, this.params.length);
+ calldata.printAnnotated();
this.bind(calldata, CalldataSection.PARAMS);
return calldata.getHexValue();
diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts
index 070bfe7f6..553fac43e 100644
--- a/packages/order-utils/test/abi_encoder_test.ts
+++ b/packages/order-utils/test/abi_encoder_test.ts
@@ -22,7 +22,7 @@ describe.only('ABI Encoder', () => {
describe.only('Just a Greg, Eh', () => {
- it.skip('Crazy ABI', async () => {
+ it('Crazy ABI', async () => {
const method = new AbiEncoder.Method(AbiSamples.crazyAbi);
console.log(method.getSignature());
@@ -211,7 +211,7 @@ describe.only('ABI Encoder', () => {
expect(calldata).to.be.equal(expectedCalldata);
});
- it.only('Static Tuple', async () => {
+ it('Static Tuple', async () => {
// This is dynamic because it has dynamic members
const method = new AbiEncoder.Method(AbiSamples.staticTupleAbi);
const calldata = method.encode([[new BigNumber(5), new BigNumber(10), new BigNumber(15), false]]);