Appeased the linter

This commit is contained in:
Greg Hysen 2019-07-30 20:55:43 +02:00
parent 884864cc58
commit 0d4dd5ff0d
6 changed files with 108 additions and 78 deletions

View File

@ -10,7 +10,7 @@
"note": "Added tests for decoding log arguments when artifact dependencies are included/excluded.",
"pr": 1995
},
{
"note": "Added tests for`getABIDecodedTransactionData` and `getABIDecodedReturnData` in contract wrappers.",
"pr": 2018

View File

@ -22,86 +22,28 @@ pragma experimental ABIEncoderV2;
contract TestAbi {
/// @dev complex input is dynamic and more difficult to decode than simple input.
struct ComplexInput {
uint256 foo;
bytes bar;
string car;
}
/// @dev complex input is dynamic and more difficult to decode than simple input.
struct ComplexOutput {
ComplexInput input;
bytes lorem;
bytes ipsum;
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 ()
external
payable
{
address addr = address(this);
assembly {
@ -138,4 +80,75 @@ contract TestAbi {
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"
);
}
}

View File

@ -2,7 +2,6 @@ import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test
import { BlockchainLifecycle } from '@0x/dev-utils';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import { DecodedLogArgs, LogWithDecodedArgs } from 'ethereum-types';
import { artifacts, TestAbiContract } from '../src';
@ -11,7 +10,7 @@ const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe.only('TestAbi', () => {
describe('TestAbi', () => {
let testAbi: TestAbiContract;
const runTestAsync = async (contractMethod: any, input: any, output: any) => {
const transaction = contractMethod.getABIEncodedTransactionData(input);
@ -64,14 +63,14 @@ describe.only('TestAbi', () => {
car: 'zoom zoom',
};
const output = {
input: input,
input,
lorem: '0x12345678',
ipsum: '0x87654321',
dolor: 'amet',
};
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 output = ['0x12345678', '0x87654321', 'amet'];
const transaction = testAbi.multiInputMultiOutput.getABIEncodedTransactionData(

View File

@ -3,7 +3,11 @@
"version": "4.5.0",
"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
}
]

View File

@ -806,7 +806,8 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const dataType = new AbiEncoder.Int(testDataItem);
const args = new BigNumber(0);
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
expect(() => {
dataType.decode(encodedArgsTruncated);

File diff suppressed because one or more lines are too long