Add prefix to names of properties in EncodingRules and DecodingRules
This commit is contained in:
parent
492e0ae345
commit
c6ff77bdd8
@ -1,4 +1,13 @@
|
||||
[
|
||||
{
|
||||
"version": "2.1.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add `should` prefix to names of properties in EncodingRules and DecodingRules",
|
||||
"pr": 1363
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.1.0",
|
||||
"changes": [
|
||||
|
@ -62,7 +62,7 @@ export abstract class AbstractSetDataType extends DataType {
|
||||
// Create a new scope in the calldata, before descending into the members of this set.
|
||||
calldata.startScope();
|
||||
let value: any[] | object;
|
||||
if (rules.structsAsObjects && !this._isArray) {
|
||||
if (rules.shouldConvertStructsToObjects && !this._isArray) {
|
||||
// Construct an object with values for each member of the set.
|
||||
value = {};
|
||||
_.each(this._memberIndexByName, (idx: number, key: string) => {
|
||||
|
@ -49,7 +49,7 @@ export class Calldata {
|
||||
throw new Error('expected root');
|
||||
}
|
||||
// Optimize, if flag set
|
||||
if (this._rules.optimize) {
|
||||
if (this._rules.shouldOptimize) {
|
||||
this._optimize();
|
||||
}
|
||||
// Set offsets
|
||||
@ -60,7 +60,9 @@ export class Calldata {
|
||||
offset += block.getSizeInBytes();
|
||||
}
|
||||
// Generate hex string
|
||||
const hexString = this._rules.annotate ? this._toHumanReadableCallData() : this._toEvmCompatibeCallDataHex();
|
||||
const hexString = this._rules.shouldAnnotate
|
||||
? this._toHumanReadableCallData()
|
||||
: this._toEvmCompatibeCallDataHex();
|
||||
return hexString;
|
||||
}
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ export const constants = {
|
||||
HEX_SELECTOR_BYTE_OFFSET_IN_CALLDATA: 0,
|
||||
// Disable no-object-literal-type-assertion so we can enforce cast
|
||||
/* tslint:disable no-object-literal-type-assertion */
|
||||
DEFAULT_DECODING_RULES: { structsAsObjects: false } as DecodingRules,
|
||||
DEFAULT_ENCODING_RULES: { optimize: true, annotate: false } as EncodingRules,
|
||||
DEFAULT_DECODING_RULES: { shouldConvertStructsToObjects: false } as DecodingRules,
|
||||
DEFAULT_ENCODING_RULES: { shouldOptimize: true, shouldAnnotate: false } as EncodingRules,
|
||||
/* tslint:enable no-object-literal-type-assertion */
|
||||
};
|
||||
|
@ -1,8 +1,8 @@
|
||||
export interface DecodingRules {
|
||||
structsAsObjects: boolean;
|
||||
shouldConvertStructsToObjects: boolean;
|
||||
}
|
||||
|
||||
export interface EncodingRules {
|
||||
optimize?: boolean;
|
||||
annotate?: boolean;
|
||||
shouldOptimize?: boolean;
|
||||
shouldAnnotate?: boolean;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
|
||||
const encodingRules: AbiEncoder.EncodingRules = { optimize: false }; // optimizer is tested separately.
|
||||
const encodingRules: AbiEncoder.EncodingRules = { shouldOptimize: false }; // optimizer is tested separately.
|
||||
describe('Array', () => {
|
||||
it('Fixed size; Static elements', async () => {
|
||||
// Create DataType object
|
||||
@ -194,7 +194,7 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
|
||||
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb0000000000000000000000000000000000000000000000000000000000000001';
|
||||
expect(encodedArgs).to.be.equal(expectedEncodedArgs);
|
||||
// Decode Encoded Args and validate result
|
||||
const decodingRules: AbiEncoder.DecodingRules = { structsAsObjects: true };
|
||||
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
|
||||
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
|
||||
expect(decodedArgs).to.be.deep.equal(args);
|
||||
});
|
||||
@ -214,7 +214,7 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
|
||||
'0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20576f726c6421000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008abcdef0123456789000000000000000000000000000000000000000000000000';
|
||||
expect(encodedArgs).to.be.equal(expectedEncodedArgs);
|
||||
// Decode Encoded Args and validate result
|
||||
const decodingRules: AbiEncoder.DecodingRules = { structsAsObjects: true };
|
||||
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
|
||||
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
|
||||
expect(decodedArgs).to.be.deep.equal(args);
|
||||
});
|
||||
@ -234,7 +234,7 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
|
||||
'0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002';
|
||||
expect(encodedArgs).to.be.equal(expectedEncodedArgs);
|
||||
// Decode Encoded Args and validate result
|
||||
const decodingRules: AbiEncoder.DecodingRules = { structsAsObjects: true };
|
||||
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
|
||||
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
|
||||
expect(decodedArgs).to.be.deep.equal(args);
|
||||
});
|
||||
@ -254,7 +254,7 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002';
|
||||
expect(encodedArgs).to.be.equal(expectedEncodedArgs);
|
||||
// Decode Encoded Args and validate result
|
||||
const decodingRules: AbiEncoder.DecodingRules = { structsAsObjects: true };
|
||||
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
|
||||
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
|
||||
expect(decodedArgs).to.be.deep.equal(args);
|
||||
});
|
||||
@ -276,7 +276,7 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
|
||||
'0x0102030400000000000000000000000000000000000000000000000000000000050607080000000000000000000000000000000000000000000000000000000009101112000000000000000000000000000000000000000000000000000000001314151600000000000000000000000000000000000000000000000000000000';
|
||||
expect(encodedArgs).to.be.equal(expectedEncodedArgs);
|
||||
// Decode Encoded Args and validate result
|
||||
const decodingRules: AbiEncoder.DecodingRules = { structsAsObjects: true };
|
||||
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
|
||||
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
|
||||
expect(decodedArgs).to.be.deep.equal(args);
|
||||
});
|
||||
@ -298,7 +298,7 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
|
||||
'0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000004010203040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040506070800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000004091011120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041314151600000000000000000000000000000000000000000000000000000000';
|
||||
expect(encodedArgs).to.be.equal(expectedEncodedArgs);
|
||||
// Decode Encoded Args and validate result
|
||||
const decodingRules: AbiEncoder.DecodingRules = { structsAsObjects: true };
|
||||
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
|
||||
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
|
||||
expect(decodedArgs).to.be.deep.equal(args);
|
||||
});
|
||||
@ -328,7 +328,7 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
|
||||
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20576f726c6421000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008abcdef0123456789000000000000000000000000000000000000000000000000';
|
||||
expect(encodedArgs).to.be.equal(expectedEncodedArgs);
|
||||
// Decode Encoded Args and validate result
|
||||
const decodingRules: AbiEncoder.DecodingRules = { structsAsObjects: true };
|
||||
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
|
||||
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
|
||||
expect(decodedArgs).to.be.deep.equal(args);
|
||||
});
|
||||
|
File diff suppressed because one or more lines are too long
@ -10,7 +10,7 @@ chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
|
||||
const encodingRules: AbiEncoder.EncodingRules = { optimize: true };
|
||||
const encodingRules: AbiEncoder.EncodingRules = { shouldOptimize: true };
|
||||
it('Duplicate Dynamic Arrays with Static Elements', async () => {
|
||||
// Generate calldata
|
||||
const method = new AbiEncoder.Method(OptimizedAbis.duplicateDynamicArraysWithStaticElements);
|
||||
@ -206,7 +206,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
|
||||
const twoDimArray2 = twoDimArray1;
|
||||
const args = [twoDimArray1, twoDimArray2];
|
||||
// Validata calldata
|
||||
const optimizedCalldata = method.encode(args, { optimize: false });
|
||||
const optimizedCalldata = method.encode(args, { shouldOptimize: false });
|
||||
const expectedOptimizedCalldata =
|
||||
'0x0d28c4f9000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000003466f6f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003426172000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035a61610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000003466f6f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003426172000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035a61610000000000000000000000000000000000000000000000000000000000';
|
||||
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
|
||||
|
@ -10,7 +10,7 @@ chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('ABI Encoder: Return Value Encoding/Decoding', () => {
|
||||
const encodingRules: AbiEncoder.EncodingRules = { optimize: false }; // optimizer is tested separately.
|
||||
const encodingRules: AbiEncoder.EncodingRules = { shouldOptimize: false }; // optimizer is tested separately.
|
||||
it('No Return Value', async () => {
|
||||
// Decode return value
|
||||
const method = new AbiEncoder.Method(ReturnValueAbis.noReturnValues);
|
||||
|
Loading…
x
Reference in New Issue
Block a user