Alias now points to dependency, not pointer

This commit is contained in:
Greg Hysen
2018-11-13 16:17:24 -08:00
parent 457cb1dc84
commit 27cb966991
3 changed files with 46 additions and 4 deletions

View File

@@ -403,7 +403,7 @@ export class Calldata {
// Optimize
const lastSubtree = subtrees[subtrees.length - 1];
for (let i = 0; i < subtrees.length - 1; ++i) {
subtrees[i].setAlias(lastSubtree);
subtrees[i].setAlias(lastSubtree.getDependency());
}
});
}
@@ -413,6 +413,8 @@ export class Calldata {
throw new Error('expected root');
}
if (optimize) this.optimize();
const offsetQueue = this.createQueue(this.root);
let block: CalldataBlock | undefined;
let offset = 0;
@@ -421,8 +423,6 @@ export class Calldata {
offset += block.getSizeInBytes();
}
if (optimize) this.optimize();
const hexValue = annotate ? this.generateAnnotatedHexString() : this.generateCondensedHexString();
return hexValue;
}

View File

@@ -27,7 +27,7 @@ const expect = chai.expect;
describe.only('ABI Encoder', () => {
describe.only('ABI Tests at Method Level', () => {
it.only('Optimizer', async () => {
it('Optimizer #1', async () => {
const method = new AbiEncoder.Method(AbiSamples.stringAbi);
const strings = [
"Test String",
@@ -41,6 +41,29 @@ describe.only('ABI Encoder', () => {
console.log(optimizedCalldata);
});
it.only('Optimizer #2', async () => {
const method = new AbiEncoder.Method(AbiSamples.optimizerAbi2);
const stringArray = [
"Test String",
"Test String",
"Test String",
"Test String",
];
const string = 'Test String';
const args = [stringArray, string];
const TEST = method.encode(args, new Calldata(), true, true);
console.log(TEST);
const optimizedCalldata = method.encode(args, new Calldata(), false, true);
console.log(`OPTIMIZED CALLDATA == '${optimizedCalldata}'`);
const decodedArgs = method.decode(optimizedCalldata);
console.log(JSON.stringify(decodedArgs));
//expect(decodedArgs).to.be.equal(args);
});
it('Crazy ABI', async () => {
const method = new AbiEncoder.Method(AbiSamples.crazyAbi);
console.log(method.getSignature());

View File

@@ -34,6 +34,25 @@ export const stringAbi = {
type: 'function',
} as MethodAbi;
export const optimizerAbi2 = {
constant: false,
inputs: [
{
name: 'stringArray',
type: 'string[]',
},
{
name: 'string',
type: 'string',
},
],
name: 'simpleFunction',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
} as MethodAbi;
export const typesWithDefaultWidthsAbi = {
constant: false,
inputs: [