aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-08 23:27:14 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commita13099bde3aa6a47516127ae7c7d9f78488a3911 (patch)
tree88f18797d5fe3f822a54b575a272024b48f485c0 /packages
parent1600820deab0636d37a9a50025576a75ae8feeec (diff)
downloaddexon-sol-tools-a13099bde3aa6a47516127ae7c7d9f78488a3911.tar.gz
dexon-sol-tools-a13099bde3aa6a47516127ae7c7d9f78488a3911.tar.zst
dexon-sol-tools-a13099bde3aa6a47516127ae7c7d9f78488a3911.zip
hack for static arrays
Diffstat (limited to 'packages')
-rw-r--r--packages/order-utils/test/abi_encoder_test.ts134
1 files changed, 78 insertions, 56 deletions
diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts
index b27dc4793..b8f1d39ad 100644
--- a/packages/order-utils/test/abi_encoder_test.ts
+++ b/packages/order-utils/test/abi_encoder_test.ts
@@ -130,7 +130,7 @@ const crazyAbi = {
{
name: 'someStaticArray',
type: 'uint8[3]',
- } /*
+ },
{
name: 'someStaticArrayWithDynamicMembers',
type: 'string[2]',
@@ -170,9 +170,9 @@ const crazyAbi = {
type: 'string',
},
//{
- // name: 'someStrArray',
- // type: 'string[]',
- /// },
+ // name: 'someStrArray',
+ // type: 'string[]',
+ /// },
{
name: 'someBytes',
type: 'bytes',
@@ -889,6 +889,15 @@ namespace AbiEncoder {
}
}
+ // @TODO: HACKY -- shouldn't really have children for a
+ public getChildren(): DataType[] {
+ if (this.isStatic()) {
+ return [];
+ } else {
+ return this.children;
+ }
+ }
+
public assignValue(value: any[]) {
// Sanity check length
const valueLength = new BigNumber(value.length);
@@ -913,26 +922,40 @@ namespace AbiEncoder {
}
}
- public getHexValue(): string {
- if (this.isLengthDefined) {
- return '0x';
- }
-
+ private getHexValueDynamicArray(): string {
const lengthBufUnpadded = ethUtil.toBuffer(`0x${this.length.toString(16)}`);
const lengthBuf = ethUtil.setLengthLeft(lengthBufUnpadded, 32);
let valueBuf = lengthBuf;
- /*for (let idx = new BigNumber(0); idx.lessThan(this.length); idx = idx.plus(1)) {
+
+ const valueHex = ethUtil.bufferToHex(valueBuf);
+ return valueHex;
+ }
+
+ private getHexValueStaticArray(): string {
+ let valueBuf = new Buffer("");
+
+ for (let idx = new BigNumber(0); idx.lessThan(this.length); idx = idx.plus(1)) {
const idxNumber = idx.toNumber();
const childValueHex = this.children[idxNumber].getHexValue();
const childValueBuf = ethUtil.toBuffer(childValueHex);
valueBuf = Buffer.concat([valueBuf, childValueBuf]);
- }*/
+
+ console.log(JSON.stringify(idx));
+ }
// Convert value buffer to hex
const valueHex = ethUtil.bufferToHex(valueBuf);
return valueHex;
}
+ public getHexValue(): string {
+ if (this.isLengthDefined) {
+ return this.getHexValueStaticArray();
+ } else {
+ return this.getHexValueDynamicArray();
+ }
+ }
+
public isStatic(): boolean {
return this.isLengthDefined;
}
@@ -1275,56 +1298,54 @@ namespace AbiEncoder {
describe.only('ABI Encoder', () => {
describe.only('Just a Greg, Eh', () => {
- it.only('Crazy ABI', async () => {
- const method = new AbiEncoder.Method(staticArrayAbi);
+ it('Crazy ABI', async () => {
+ const method = new AbiEncoder.Method(crazyAbi);
console.log(method.getSignature());
- const args = [[new BigNumber(127), new BigNumber(14), new BigNumber(54)]];
-
- const a2 = [
+ const args = [[new BigNumber(127), new BigNumber(14), new BigNumber(54)],
+ [
+ 'the little piping piper piped a piping pipper papper',
+ 'the kid knows how to write poems, what can I say -- I guess theres a lot I could say to try to fill this line with a lot of text.',
+ ], // l
+ [
+ '0x38745637834987324827439287423897238947239847',
+ '0x7283472398237423984723984729847248927498748974284728947239487498749847874329423743492347329847239842374892374892374892347238947289478947489374289472894738942749823743298742389472389473289472389437249823749823742893472398',
+ '0x283473298473248923749238742398742398472894729843278942374982374892374892743982',
+ ], // m
+ [
+ [
+ 'some string',
+ 'some another string',
+ 'there are just too many stringsup in',
+ 'here',
+ 'yall ghonna make me lose my mind',
+ ],
[
'the little piping piper piped a piping pipper papper',
'the kid knows how to write poems, what can I say -- I guess theres a lot I could say to try to fill this line with a lot of text.',
- ], // l
- [
- '0x38745637834987324827439287423897238947239847',
- '0x7283472398237423984723984729847248927498748974284728947239487498749847874329423743492347329847239842374892374892374892347238947289478947489374289472894738942749823743298742389472389473289472389437249823749823742893472398',
- '0x283473298473248923749238742398742398472894729843278942374982374892374892743982',
- ], // m
- [
- [
- 'some string',
- 'some another string',
- 'there are just too many stringsup in',
- 'here',
- 'yall ghonna make me lose my mind',
- ],
+ ],
+ [],
+ ], // n
+ [
+ new BigNumber(4037824789),
+ 'the kid knows how to write poems, what can I say -- I guess theres a lot I could say to try to fill this line with a lot of text.',
+ ], // o
+ [
+ new BigNumber('239048320948320948230', 10),
+ 'akdhjasjkdhasjkldshdjahdkjsahdajksdhsajkdhsajkdhadjkashdjksadhajkdhsajkdhsadjk',
+ /*[
[
- 'the little piping piper piped a piping pipper papper',
- 'the kid knows how to write poems, what can I say -- I guess theres a lot I could say to try to fill this line with a lot of text.',
+ '23432423342',
+ 'skdjfhdsjkfdhsfkjsdhfjkdshfdsjkfhsdjkfhsdjkfhdsjkfhdsjfhsdfjdshjkfsdhf',
+ 'sdfsdfdfdffsdf',
],
[],
- ], // n
- [
- new BigNumber(4037824789),
- 'the kid knows how to write poems, what can I say -- I guess theres a lot I could say to try to fill this line with a lot of text.',
- ], // o
- [
- new BigNumber('239048320948320948230', 10),
- 'akdhjasjkdhasjkldshdjahdkjsahdajksdhsajkdhsajkdhadjkashdjksadhajkdhsajkdhsadjk',
- /*[
- [
- '23432423342',
- 'skdjfhdsjkfdhsfkjsdhfjkdshfdsjkfhsdjkfhsdjkfhdsjkfhdsjfhsdfjdshjkfsdhf',
- 'sdfsdfdfdffsdf',
- ],
- [],
- [],
- ['23ehsdjkfhsiufhwfuefhesfhauhesufheuifhsefushfsufehfeuif'],
- ],*/
- '0xf74848484848484848484848484848484848483847576879809433994458585848932091',
- '0xe41d2489571d322189246dafa5ebde1f4699f498',
- ], // p
+ [],
+ ['23ehsdjkfhsiufhwfuefhesfhauhesufheuifhsefushfsufehfeuif'],
+ ],*/
+ '0xf74848484848484848484848484848484848483847576879809433994458585848932091',
+ '0xe41d2489571d322189246dafa5ebde1f4699f498',
+ ], // p
/*[
[
new BigNumber('23904848320948230', 10),
@@ -1367,11 +1388,12 @@ describe.only('ABI Encoder', () => {
console.log(calldata);
console.log('*'.repeat(40));
console.log(JSON.stringify(args));
+ console.log(method.getSignature());
+ /*
const expectedCalldata =
- '0xf68ade72000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000036';
-
- expect(calldata).to.be.equal(expectedCalldata);
+ '0x30e1f844000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000003600000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000008600000000000000000000000000000000000000000000000000000000000000960000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000034746865206c6974746c6520706970696e67207069706572207069706564206120706970696e6720706970706572207061707065720000000000000000000000000000000000000000000000000000000000000000000000000000000000000081746865206b6964206b6e6f777320686f7720746f20777269746520706f656d732c20776861742063616e204920736179202d2d2049206775657373207468657265732061206c6f74204920636f756c642073617920746f2074727920746f2066696c6c2074686973206c696e6520776974682061206c6f74206f6620746578742e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000163874563783498732482743928742389723894723984700000000000000000000000000000000000000000000000000000000000000000000000000000000006e72834723982374239847239847298472489274987489742847289472394874987498478743294237434923473298472398423748923748923748923472389472894789474893742894728947389427498237432987423894723894732894723894372498237498237428934723980000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000027283473298473248923749238742398742398472894729843278942374982374892374892743982000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000000b736f6d6520737472696e670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013736f6d6520616e6f7468657220737472696e67000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024746865726520617265206a75737420746f6f206d616e7920737472696e6773757020696e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046865726500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002079616c6c2067686f6e6e61206d616b65206d65206c6f7365206d79206d696e640000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000034746865206c6974746c6520706970696e67207069706572207069706564206120706970696e6720706970706572207061707065720000000000000000000000000000000000000000000000000000000000000000000000000000000000000081746865206b6964206b6e6f777320686f7720746f20777269746520706f656d732c20776861742063616e204920736179202d2d2049206775657373207468657265732061206c6f74204920636f756c642073617920746f2074727920746f2066696c6c2074686973206c696e6520776974682061206c6f74206f6620746578742e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f0ac511500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000081746865206b6964206b6e6f777320686f7720746f20777269746520706f656d732c20776861742063616e204920736179202d2d2049206775657373207468657265732061206c6f74204920636f756c642073617920746f2074727920746f2066696c6c2074686973206c696e6520776974682061206c6f74206f6620746578742e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cf5763d5ec63d500600000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498000000000000000000000000000000000000000000000000000000000000004e616b64686a61736a6b646861736a6b6c647368646a6168646b6a73616864616a6b73646873616a6b646873616a6b646861646a6b617368646a6b73616468616a6b646873616a6b64687361646a6b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024f7484848484848484848484848484848484848384757687980943399445858584893209100000000000000000000000000000000000000000000000000000000';
+ expect(calldata).to.be.equal(expectedCalldata);*/
/*const calldata = method.encode([{ someUint: new BigNumber(5), someStr: 'five' }]);
console.log(method.getSignature());