Appeased the linter
This commit is contained in:
parent
884864cc58
commit
0d4dd5ff0d
@ -10,7 +10,7 @@
|
|||||||
"note": "Added tests for decoding log arguments when artifact dependencies are included/excluded.",
|
"note": "Added tests for decoding log arguments when artifact dependencies are included/excluded.",
|
||||||
"pr": 1995
|
"pr": 1995
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"note": "Added tests for`getABIDecodedTransactionData` and `getABIDecodedReturnData` in contract wrappers.",
|
"note": "Added tests for`getABIDecodedTransactionData` and `getABIDecodedReturnData` in contract wrappers.",
|
||||||
"pr": 2018
|
"pr": 2018
|
||||||
|
@ -22,86 +22,28 @@ pragma experimental ABIEncoderV2;
|
|||||||
|
|
||||||
contract TestAbi {
|
contract TestAbi {
|
||||||
|
|
||||||
|
/// @dev complex input is dynamic and more difficult to decode than simple input.
|
||||||
struct ComplexInput {
|
struct ComplexInput {
|
||||||
uint256 foo;
|
uint256 foo;
|
||||||
bytes bar;
|
bytes bar;
|
||||||
string car;
|
string car;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @dev complex input is dynamic and more difficult to decode than simple input.
|
||||||
struct ComplexOutput {
|
struct ComplexOutput {
|
||||||
ComplexInput input;
|
ComplexInput input;
|
||||||
bytes lorem;
|
bytes lorem;
|
||||||
bytes ipsum;
|
bytes ipsum;
|
||||||
string dolor;
|
string dolor;
|
||||||
}
|
}
|
||||||
|
|
||||||
function noInputNoOutput()
|
|
||||||
public
|
|
||||||
pure
|
|
||||||
{
|
|
||||||
// NOP
|
|
||||||
require(true == true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function noInputSimpleOutput()
|
|
||||||
public
|
|
||||||
pure
|
|
||||||
returns (uint256)
|
|
||||||
{
|
|
||||||
return 1991;
|
|
||||||
}
|
|
||||||
|
|
||||||
function simpleInputNoOutput(uint256)
|
|
||||||
public
|
|
||||||
pure
|
|
||||||
{
|
|
||||||
// NOP
|
|
||||||
require(true == true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function simpleInputSimpleOutput(uint256)
|
|
||||||
public
|
|
||||||
pure
|
|
||||||
returns (uint256)
|
|
||||||
{
|
|
||||||
return 1991;
|
|
||||||
}
|
|
||||||
|
|
||||||
function complexInputComplexOutput(ComplexInput memory complexInput)
|
|
||||||
public
|
|
||||||
pure
|
|
||||||
returns (ComplexOutput memory)
|
|
||||||
{
|
|
||||||
return ComplexOutput({
|
|
||||||
input: complexInput,
|
|
||||||
lorem: hex'12345678',
|
|
||||||
ipsum: hex'87654321',
|
|
||||||
dolor: "amet"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function multiInputMultiOutput(
|
|
||||||
uint256,
|
|
||||||
bytes memory,
|
|
||||||
string memory
|
|
||||||
)
|
|
||||||
public
|
|
||||||
pure
|
|
||||||
returns (
|
|
||||||
bytes memory,
|
|
||||||
bytes memory,
|
|
||||||
string memory
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return (
|
|
||||||
hex'12345678',
|
|
||||||
hex'87654321',
|
|
||||||
"amet"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/// @dev The fallback function calls into this contract and executes one of the above functions.
|
||||||
|
/// This allows us to test `getABIDecodedTransactionData` and `getABIDecodedReturnData` that is
|
||||||
|
/// include in contract wrappers.
|
||||||
|
// solhint-disable no-complex-fallback
|
||||||
function ()
|
function ()
|
||||||
external
|
external
|
||||||
|
payable
|
||||||
{
|
{
|
||||||
address addr = address(this);
|
address addr = address(this);
|
||||||
assembly {
|
assembly {
|
||||||
@ -138,4 +80,75 @@ contract TestAbi {
|
|||||||
return(0, returndatasize())
|
return(0, returndatasize())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @dev Tests decoding when both input and output are empty.
|
||||||
|
function noInputNoOutput()
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
{
|
||||||
|
// NOP
|
||||||
|
require(true == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Tests decoding when input is empty and output is non-empty.
|
||||||
|
function noInputSimpleOutput()
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
returns (uint256)
|
||||||
|
{
|
||||||
|
return 1991;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Tests decoding when input is not empty but output is empty.
|
||||||
|
function simpleInputNoOutput(uint256)
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
{
|
||||||
|
// NOP
|
||||||
|
require(true == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Tests decoding when both input and output are non-empty.
|
||||||
|
function simpleInputSimpleOutput(uint256)
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
returns (uint256)
|
||||||
|
{
|
||||||
|
return 1991;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Tests decoding when the input and output are complex.
|
||||||
|
function complexInputComplexOutput(ComplexInput memory complexInput)
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
returns (ComplexOutput memory)
|
||||||
|
{
|
||||||
|
return ComplexOutput({
|
||||||
|
input: complexInput,
|
||||||
|
lorem: hex'12345678',
|
||||||
|
ipsum: hex'87654321',
|
||||||
|
dolor: "amet"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @dev Tests decoding when the input and output are complex and have more than one argument.
|
||||||
|
function multiInputMultiOutput(
|
||||||
|
uint256,
|
||||||
|
bytes memory,
|
||||||
|
string memory
|
||||||
|
)
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
returns (
|
||||||
|
bytes memory,
|
||||||
|
bytes memory,
|
||||||
|
string memory
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
hex'12345678',
|
||||||
|
hex'87654321',
|
||||||
|
"amet"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test
|
|||||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import { DecodedLogArgs, LogWithDecodedArgs } from 'ethereum-types';
|
|
||||||
|
|
||||||
import { artifacts, TestAbiContract } from '../src';
|
import { artifacts, TestAbiContract } from '../src';
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ const expect = chai.expect;
|
|||||||
|
|
||||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||||
|
|
||||||
describe.only('TestAbi', () => {
|
describe('TestAbi', () => {
|
||||||
let testAbi: TestAbiContract;
|
let testAbi: TestAbiContract;
|
||||||
const runTestAsync = async (contractMethod: any, input: any, output: any) => {
|
const runTestAsync = async (contractMethod: any, input: any, output: any) => {
|
||||||
const transaction = contractMethod.getABIEncodedTransactionData(input);
|
const transaction = contractMethod.getABIEncodedTransactionData(input);
|
||||||
@ -64,14 +63,14 @@ describe.only('TestAbi', () => {
|
|||||||
car: 'zoom zoom',
|
car: 'zoom zoom',
|
||||||
};
|
};
|
||||||
const output = {
|
const output = {
|
||||||
input: input,
|
input,
|
||||||
lorem: '0x12345678',
|
lorem: '0x12345678',
|
||||||
ipsum: '0x87654321',
|
ipsum: '0x87654321',
|
||||||
dolor: 'amet',
|
dolor: 'amet',
|
||||||
};
|
};
|
||||||
await runTestAsync(testAbi.complexInputComplexOutput, input, output);
|
await runTestAsync(testAbi.complexInputComplexOutput, input, output);
|
||||||
});
|
});
|
||||||
it('should successfully encode/decode (complex input / complex output)', async () => {
|
it('should successfully encode/decode (multi-input / multi-output)', async () => {
|
||||||
const input = [new BigNumber(1991), '0x1234', 'zoom zoom'];
|
const input = [new BigNumber(1991), '0x1234', 'zoom zoom'];
|
||||||
const output = ['0x12345678', '0x87654321', 'amet'];
|
const output = ['0x12345678', '0x87654321', 'amet'];
|
||||||
const transaction = testAbi.multiInputMultiOutput.getABIEncodedTransactionData(
|
const transaction = testAbi.multiInputMultiOutput.getABIEncodedTransactionData(
|
||||||
|
@ -3,7 +3,11 @@
|
|||||||
"version": "4.5.0",
|
"version": "4.5.0",
|
||||||
"changes": [
|
"changes": [
|
||||||
{
|
{
|
||||||
"note": "updated to include `strictDecode` for decoding method arguments",
|
"note": "Updated to include `strictDecode` for decoding method arguments",
|
||||||
|
"pr": 2018
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"note": "Throw exception when trying to decode beyond boundaries of calldata",
|
||||||
"pr": 2018
|
"pr": 2018
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -806,7 +806,8 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
|
|||||||
const dataType = new AbiEncoder.Int(testDataItem);
|
const dataType = new AbiEncoder.Int(testDataItem);
|
||||||
const args = new BigNumber(0);
|
const args = new BigNumber(0);
|
||||||
const encodedArgs = dataType.encode(args, encodingRules);
|
const encodedArgs = dataType.encode(args, encodingRules);
|
||||||
const encodedArgsTruncated = encodedArgs.substr(0, 60);
|
const truncatedCalldataLength = 60;
|
||||||
|
const encodedArgsTruncated = encodedArgs.substr(0, truncatedCalldataLength);
|
||||||
// Encode Args and validate result
|
// Encode Args and validate result
|
||||||
expect(() => {
|
expect(() => {
|
||||||
dataType.decode(encodedArgsTruncated);
|
dataType.decode(encodedArgsTruncated);
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user