Remove obsoleted code from 0x/contracts-utils (#643)

* Remove TestAuthorizable

* Remove contracts/utils Authorizable and IAuthorizable

* Remove contracts/utils D18 contract

* Remove contracts/utils LibAddress contracts

* Remove contracts/utils LogDecoding contracts

* Remove contracts/utils Refundable contracts

* Remove contracts/utils LibAuthorizableRichErrors contracts

* Remove contracts/utils EIP712 contracts

* Remove contracts/utils TestRefundableReceiver contracts

* Remove contracts/utils EIP1271 contracts

* Remove contracts/utils ReentrancyGuardV06 contracts

* Remove contracts/utils LibMath contracts

* Remove contracts/utils LibFractions contracts

* Remove contracts/utils LibMathRichErrors contracts

* Remove DeploymentConstants as per PR review
https://github.com/0xProject/protocol/pull/643#pullrequestreview-1264963784
This commit is contained in:
Elena
2023-02-06 19:35:39 +02:00
committed by GitHub
parent a472125c65
commit c4b1f043c6
39 changed files with 3 additions and 3322 deletions

View File

@@ -5,21 +5,13 @@
*/
import { ContractArtifact } from 'ethereum-types';
import * as Authorizable from '../test/generated-artifacts/Authorizable.json';
import * as AuthorizableV06 from '../test/generated-artifacts/AuthorizableV06.json';
import * as AuthorizableV08 from '../test/generated-artifacts/AuthorizableV08.json';
import * as D18 from '../test/generated-artifacts/D18.json';
import * as DeploymentConstants from '../test/generated-artifacts/DeploymentConstants.json';
import * as IAuthorizable from '../test/generated-artifacts/IAuthorizable.json';
import * as IAuthorizableV06 from '../test/generated-artifacts/IAuthorizableV06.json';
import * as IAuthorizableV08 from '../test/generated-artifacts/IAuthorizableV08.json';
import * as IOwnable from '../test/generated-artifacts/IOwnable.json';
import * as IOwnableV06 from '../test/generated-artifacts/IOwnableV06.json';
import * as IOwnableV08 from '../test/generated-artifacts/IOwnableV08.json';
import * as LibAddress from '../test/generated-artifacts/LibAddress.json';
import * as LibAddressArray from '../test/generated-artifacts/LibAddressArray.json';
import * as LibAddressArrayRichErrors from '../test/generated-artifacts/LibAddressArrayRichErrors.json';
import * as LibAuthorizableRichErrors from '../test/generated-artifacts/LibAuthorizableRichErrors.json';
import * as LibAuthorizableRichErrorsV06 from '../test/generated-artifacts/LibAuthorizableRichErrorsV06.json';
import * as LibAuthorizableRichErrorsV08 from '../test/generated-artifacts/LibAuthorizableRichErrorsV08.json';
import * as LibBytes from '../test/generated-artifacts/LibBytes.json';
@@ -28,11 +20,6 @@ import * as LibBytesRichErrorsV06 from '../test/generated-artifacts/LibBytesRich
import * as LibBytesRichErrorsV08 from '../test/generated-artifacts/LibBytesRichErrorsV08.json';
import * as LibBytesV06 from '../test/generated-artifacts/LibBytesV06.json';
import * as LibBytesV08 from '../test/generated-artifacts/LibBytesV08.json';
import * as LibEIP1271 from '../test/generated-artifacts/LibEIP1271.json';
import * as LibEIP712 from '../test/generated-artifacts/LibEIP712.json';
import * as LibFractions from '../test/generated-artifacts/LibFractions.json';
import * as LibMath from '../test/generated-artifacts/LibMath.json';
import * as LibMathRichErrors from '../test/generated-artifacts/LibMathRichErrors.json';
import * as LibMathRichErrorsV06 from '../test/generated-artifacts/LibMathRichErrorsV06.json';
import * as LibMathRichErrorsV08 from '../test/generated-artifacts/LibMathRichErrorsV08.json';
import * as LibMathV06 from '../test/generated-artifacts/LibMathV06.json';
@@ -55,38 +42,15 @@ import * as Ownable from '../test/generated-artifacts/Ownable.json';
import * as OwnableV06 from '../test/generated-artifacts/OwnableV06.json';
import * as OwnableV08 from '../test/generated-artifacts/OwnableV08.json';
import * as ReentrancyGuard from '../test/generated-artifacts/ReentrancyGuard.json';
import * as ReentrancyGuardV06 from '../test/generated-artifacts/ReentrancyGuardV06.json';
import * as ReentrancyGuardV08 from '../test/generated-artifacts/ReentrancyGuardV08.json';
import * as Refundable from '../test/generated-artifacts/Refundable.json';
import * as TestAuthorizable from '../test/generated-artifacts/TestAuthorizable.json';
import * as TestLibAddress from '../test/generated-artifacts/TestLibAddress.json';
import * as TestLibAddressArray from '../test/generated-artifacts/TestLibAddressArray.json';
import * as TestLibBytes from '../test/generated-artifacts/TestLibBytes.json';
import * as TestLibEIP712 from '../test/generated-artifacts/TestLibEIP712.json';
import * as TestLibMath from '../test/generated-artifacts/TestLibMath.json';
import * as TestLibRichErrors from '../test/generated-artifacts/TestLibRichErrors.json';
import * as TestLibSafeMath from '../test/generated-artifacts/TestLibSafeMath.json';
import * as TestLogDecoding from '../test/generated-artifacts/TestLogDecoding.json';
import * as TestLogDecodingDownstream from '../test/generated-artifacts/TestLogDecodingDownstream.json';
import * as TestOwnable from '../test/generated-artifacts/TestOwnable.json';
import * as TestReentrancyGuard from '../test/generated-artifacts/TestReentrancyGuard.json';
import * as TestRefundable from '../test/generated-artifacts/TestRefundable.json';
import * as TestRefundableReceiver from '../test/generated-artifacts/TestRefundableReceiver.json';
export const artifacts = {
Authorizable: Authorizable as ContractArtifact,
D18: D18 as ContractArtifact,
DeploymentConstants: DeploymentConstants as ContractArtifact,
LibAddress: LibAddress as ContractArtifact,
LibAddressArray: LibAddressArray as ContractArtifact,
LibAddressArrayRichErrors: LibAddressArrayRichErrors as ContractArtifact,
LibAuthorizableRichErrors: LibAuthorizableRichErrors as ContractArtifact,
LibBytes: LibBytes as ContractArtifact,
LibBytesRichErrors: LibBytesRichErrors as ContractArtifact,
LibEIP1271: LibEIP1271 as ContractArtifact,
LibEIP712: LibEIP712 as ContractArtifact,
LibFractions: LibFractions as ContractArtifact,
LibMath: LibMath as ContractArtifact,
LibMathRichErrors: LibMathRichErrors as ContractArtifact,
LibOwnableRichErrors: LibOwnableRichErrors as ContractArtifact,
LibReentrancyGuardRichErrors: LibReentrancyGuardRichErrors as ContractArtifact,
LibRichErrors: LibRichErrors as ContractArtifact,
@@ -94,15 +58,12 @@ export const artifacts = {
LibSafeMathRichErrors: LibSafeMathRichErrors as ContractArtifact,
Ownable: Ownable as ContractArtifact,
ReentrancyGuard: ReentrancyGuard as ContractArtifact,
Refundable: Refundable as ContractArtifact,
IAuthorizable: IAuthorizable as ContractArtifact,
IOwnable: IOwnable as ContractArtifact,
AuthorizableV06: AuthorizableV06 as ContractArtifact,
LibBytesV06: LibBytesV06 as ContractArtifact,
LibMathV06: LibMathV06 as ContractArtifact,
LibSafeMathV06: LibSafeMathV06 as ContractArtifact,
OwnableV06: OwnableV06 as ContractArtifact,
ReentrancyGuardV06: ReentrancyGuardV06 as ContractArtifact,
LibAuthorizableRichErrorsV06: LibAuthorizableRichErrorsV06 as ContractArtifact,
LibBytesRichErrorsV06: LibBytesRichErrorsV06 as ContractArtifact,
LibMathRichErrorsV06: LibMathRichErrorsV06 as ContractArtifact,
@@ -126,18 +87,9 @@ export const artifacts = {
LibSafeMathRichErrorsV08: LibSafeMathRichErrorsV08 as ContractArtifact,
IAuthorizableV08: IAuthorizableV08 as ContractArtifact,
IOwnableV08: IOwnableV08 as ContractArtifact,
TestAuthorizable: TestAuthorizable as ContractArtifact,
TestLibAddress: TestLibAddress as ContractArtifact,
TestLibAddressArray: TestLibAddressArray as ContractArtifact,
TestLibBytes: TestLibBytes as ContractArtifact,
TestLibEIP712: TestLibEIP712 as ContractArtifact,
TestLibMath: TestLibMath as ContractArtifact,
TestLibRichErrors: TestLibRichErrors as ContractArtifact,
TestLibSafeMath: TestLibSafeMath as ContractArtifact,
TestLogDecoding: TestLogDecoding as ContractArtifact,
TestLogDecodingDownstream: TestLogDecodingDownstream as ContractArtifact,
TestOwnable: TestOwnable as ContractArtifact,
TestReentrancyGuard: TestReentrancyGuard as ContractArtifact,
TestRefundable: TestRefundable as ContractArtifact,
TestRefundableReceiver: TestRefundableReceiver as ContractArtifact,
};

View File

@@ -1,165 +0,0 @@
import { blockchainTests, constants, expect } from '@0x/contracts-test-utils';
import { AuthorizableRevertErrors, BigNumber, OwnableRevertErrors } from '@0x/utils';
import * as _ from 'lodash';
import { artifacts } from './artifacts';
import { TestAuthorizableContract } from './wrappers';
blockchainTests.resets('Authorizable', env => {
let owner: string;
let notOwner: string;
let address: string;
let authorizable: TestAuthorizableContract;
before(async () => {
const accounts = await env.getAccountAddressesAsync();
[owner, address, notOwner] = _.slice(accounts, 0, 3);
authorizable = await TestAuthorizableContract.deployFrom0xArtifactAsync(
artifacts.TestAuthorizable,
env.provider,
env.txDefaults,
artifacts,
);
});
describe('addAuthorizedAddress', () => {
it('should revert if not called by owner', async () => {
const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner);
const tx = authorizable.addAuthorizedAddress(notOwner).sendTransactionAsync({ from: notOwner });
return expect(tx).to.revertWith(expectedError);
});
it('should allow owner to add an authorized address', async () => {
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
const isAuthorized = await authorizable.authorized(address).callAsync();
expect(isAuthorized).to.be.true();
});
it('should revert if owner attempts to authorize the zero address', async () => {
const expectedError = new AuthorizableRevertErrors.ZeroCantBeAuthorizedError();
const tx = authorizable.addAuthorizedAddress(constants.NULL_ADDRESS).sendTransactionAsync({ from: owner });
return expect(tx).to.revertWith(expectedError);
});
it('should revert if owner attempts to authorize a duplicate address', async () => {
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
const expectedError = new AuthorizableRevertErrors.TargetAlreadyAuthorizedError(address);
const tx = authorizable.addAuthorizedAddress(address).sendTransactionAsync({ from: owner });
return expect(tx).to.revertWith(expectedError);
});
});
describe('onlyAuthorized', () => {
before(async () => {
await authorizable.addAuthorizedAddress(owner).awaitTransactionSuccessAsync({ from: owner });
});
after(async () => {
await authorizable.removeAuthorizedAddress(owner).awaitTransactionSuccessAsync({ from: owner });
});
it('should revert if sender is not authorized', async () => {
const tx = authorizable.onlyAuthorizedFn().callAsync({ from: notOwner });
const expectedError = new AuthorizableRevertErrors.SenderNotAuthorizedError(notOwner);
return expect(tx).to.revertWith(expectedError);
});
it('should succeed if sender is authorized', async () => {
await authorizable.onlyAuthorizedFn().callAsync({ from: owner });
});
});
describe('removeAuthorizedAddress', () => {
it('should revert if not called by owner', async () => {
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner);
const tx = authorizable.removeAuthorizedAddress(address).sendTransactionAsync({ from: notOwner });
return expect(tx).to.revertWith(expectedError);
});
it('should allow owner to remove an authorized address', async () => {
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
await authorizable.removeAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
const isAuthorized = await authorizable.authorized(address).callAsync();
expect(isAuthorized).to.be.false();
});
it('should revert if owner attempts to remove an address that is not authorized', async () => {
const expectedError = new AuthorizableRevertErrors.TargetNotAuthorizedError(address);
const tx = authorizable.removeAuthorizedAddress(address).sendTransactionAsync({ from: owner });
return expect(tx).to.revertWith(expectedError);
});
});
describe('removeAuthorizedAddressAtIndex', () => {
it('should revert if not called by owner', async () => {
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
const index = new BigNumber(0);
const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner);
const tx = authorizable.removeAuthorizedAddressAtIndex(address, index).sendTransactionAsync({
from: notOwner,
});
return expect(tx).to.revertWith(expectedError);
});
it('should revert if index is >= authorities.length', async () => {
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
const index = new BigNumber(1);
const expectedError = new AuthorizableRevertErrors.IndexOutOfBoundsError(index, index);
const tx = authorizable.removeAuthorizedAddressAtIndex(address, index).sendTransactionAsync({
from: owner,
});
return expect(tx).to.revertWith(expectedError);
});
it('should revert if owner attempts to remove an address that is not authorized', async () => {
const index = new BigNumber(0);
const expectedError = new AuthorizableRevertErrors.TargetNotAuthorizedError(address);
const tx = authorizable.removeAuthorizedAddressAtIndex(address, index).sendTransactionAsync({
from: owner,
});
return expect(tx).to.revertWith(expectedError);
});
it('should revert if address at index does not match target', async () => {
const address1 = address;
const address2 = notOwner;
await authorizable.addAuthorizedAddress(address1).awaitTransactionSuccessAsync({ from: owner });
await authorizable.addAuthorizedAddress(address2).awaitTransactionSuccessAsync({ from: owner });
const address1Index = new BigNumber(0);
const expectedError = new AuthorizableRevertErrors.AuthorizedAddressMismatchError(address1, address2);
const tx = authorizable.removeAuthorizedAddressAtIndex(address2, address1Index).sendTransactionAsync({
from: owner,
});
return expect(tx).to.revertWith(expectedError);
});
it('should allow owner to remove an authorized address', async () => {
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
const index = new BigNumber(0);
await authorizable.removeAuthorizedAddressAtIndex(address, index).awaitTransactionSuccessAsync({
from: owner,
});
const isAuthorized = await authorizable.authorized(address).callAsync();
expect(isAuthorized).to.be.false();
});
});
describe('getAuthorizedAddresses', () => {
it('should return correct authorized addresses', async () => {
// Initial Authorities
let authorities = await authorizable.getAuthorizedAddresses().callAsync();
expect(authorities).to.be.deep.eq([]);
// Authorities after addition
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
authorities = await authorizable.getAuthorizedAddresses().callAsync();
expect(authorities).to.be.deep.eq([address]);
// Authorities after removal
await authorizable.removeAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
authorities = await authorizable.getAuthorizedAddresses().callAsync();
expect(authorities).to.be.deep.eq([]);
});
});
});

View File

@@ -1,43 +0,0 @@
import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import * as chai from 'chai';
import { artifacts } from './artifacts';
import { TestLibAddressContract } from './wrappers';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('LibAddress', () => {
let lib: TestLibAddressContract;
let nonContract: string;
before(async () => {
await blockchainLifecycle.startAsync();
nonContract = (await web3Wrapper.getAvailableAddressesAsync())[0];
// Deploy LibAddress
lib = await TestLibAddressContract.deployFrom0xArtifactAsync(
artifacts.TestLibAddress,
provider,
txDefaults,
{},
);
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
describe('isContract', () => {
it('should return false for a non-contract address', async () => {
const isContract = await lib.externalIsContract(nonContract).callAsync();
expect(isContract).to.be.false();
});
it('should return true for a non-contract address', async () => {
const isContract = await lib.externalIsContract(lib.address).callAsync();
expect(isContract).to.be.true();
});
});
});

View File

@@ -1,144 +0,0 @@
import { chaiSetup, provider, randomAddress, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { BigNumber, LibAddressArrayRevertErrors } from '@0x/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import { artifacts } from './artifacts';
import { TestLibAddressArrayContract } from './wrappers';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('LibAddressArray', () => {
let lib: TestLibAddressArrayContract;
before(async () => {
await blockchainLifecycle.startAsync();
// Deploy LibAddressArray
lib = await TestLibAddressArrayContract.deployFrom0xArtifactAsync(
artifacts.TestLibAddressArray,
provider,
txDefaults,
artifacts,
);
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
describe('append', () => {
it('should append to empty array', async () => {
const addr = randomAddress();
const result = await lib.publicAppend([], addr).callAsync();
const expected = [addr];
expect(result).to.deep.equal(expected);
});
it('should append to non-empty array', async () => {
const arr = _.times(3, () => randomAddress());
const addr = randomAddress();
const expected = [...arr, addr];
const result = await lib.publicAppend(arr, addr).callAsync();
expect(result).to.deep.equal(expected);
});
it('should revert if the free memory pointer was moved to before the end of the array', async () => {
const arr = _.times(3, () => randomAddress());
const addr = randomAddress();
const freeMemOffset = new BigNumber(-1);
const addressArrayEndPtr = new BigNumber(256);
const expectedError = new LibAddressArrayRevertErrors.MismanagedMemoryError(
addressArrayEndPtr.plus(freeMemOffset),
addressArrayEndPtr,
);
return expect(lib.testAppendRealloc(arr, freeMemOffset, addr).callAsync()).to.revertWith(expectedError);
});
it('should keep the same memory address if free memory pointer does not move', async () => {
const arr = _.times(3, () => randomAddress());
const addr = randomAddress();
const freeMemOffset = new BigNumber(0);
const expected = [...arr, addr];
const [result, oldArrayMemStart, newArrayMemStart] = await lib
.testAppendRealloc(arr, freeMemOffset, addr)
.callAsync();
expect(result).to.deep.equal(expected);
expect(newArrayMemStart).bignumber.to.be.equal(oldArrayMemStart);
});
it('should change memory address if free memory pointer advances', async () => {
const arr = _.times(3, () => randomAddress());
const addr = randomAddress();
const freeMemOffset = new BigNumber(1);
const expectedArray = [...arr, addr];
const [result, oldArrayMemStart, newArrayMemStart] = await lib
.testAppendRealloc(arr, freeMemOffset, addr)
.callAsync();
// The new location should be the end of the old array + freeMemOffset.
const expectedNewArrayMemStart = oldArrayMemStart.plus((arr.length + 1) * 32).plus(freeMemOffset);
expect(result).to.deep.equal(expectedArray);
expect(newArrayMemStart).bignumber.to.be.equal(expectedNewArrayMemStart);
});
});
describe('contains', () => {
it('should return false on an empty array', async () => {
const addr = randomAddress();
const isFound = await lib.publicContains([], addr).callAsync();
expect(isFound).to.equal(false);
});
it('should return false on a missing item', async () => {
const arr = _.times(3, () => randomAddress());
const addr = randomAddress();
const isFound = await lib.publicContains(arr, addr).callAsync();
expect(isFound).to.equal(false);
});
it('should return true on an included item', async () => {
const arr = _.times(4, () => randomAddress());
const addr = _.sample(arr) as string;
const isFound = await lib.publicContains(arr, addr).callAsync();
expect(isFound).to.equal(true);
});
it('should return true on the only item in the array', async () => {
const arr = _.times(1, () => randomAddress());
const isFound = await lib.publicContains(arr, arr[0]).callAsync();
expect(isFound).to.equal(true);
});
});
describe('indexOf', () => {
it('should fail on an empty array', async () => {
const addr = randomAddress();
const [isSuccess] = await lib.publicIndexOf([], addr).callAsync();
expect(isSuccess).to.equal(false);
});
it('should fail on a missing item', async () => {
const arr = _.times(3, () => randomAddress());
const addr = randomAddress();
const [isSuccess] = await lib.publicIndexOf(arr, addr).callAsync();
expect(isSuccess).to.equal(false);
});
it('should succeed on an included item', async () => {
const arr = _.times(4, () => randomAddress());
const expectedIndexOf = _.random(0, arr.length - 1);
const addr = arr[expectedIndexOf];
const [isSuccess, index] = await lib.publicIndexOf(arr, addr).callAsync();
expect(isSuccess).to.equal(true);
expect(index).bignumber.to.equal(expectedIndexOf);
});
it('should succeed on the only item in the array', async () => {
const arr = _.times(1, () => randomAddress());
const [isSuccess, index] = await lib.publicIndexOf(arr, arr[0]).callAsync();
expect(isSuccess).to.equal(true);
expect(index).bignumber.to.equal(0);
});
});
});

View File

@@ -1,108 +0,0 @@
import { chaiSetup, constants, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { BigNumber, hexUtils, signTypedDataUtils } from '@0x/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import { artifacts } from './artifacts';
import { TestLibEIP712Contract } from './wrappers';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('LibEIP712', () => {
let lib: TestLibEIP712Contract;
before(async () => {
await blockchainLifecycle.startAsync();
// Deploy LibEIP712
lib = await TestLibEIP712Contract.deployFrom0xArtifactAsync(artifacts.TestLibEIP712, provider, txDefaults, {});
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
/**
* Tests a specific instance of EIP712 domain hashing.
* @param lib The LibEIP712 contract to call.
* @param name The name of the domain.
* @param version The version of the domain.
* @param chainId The chain id of the domain.
* @param verifyingContract The verifying contract address of the domain.
*/
async function testHashEIP712DomainAsync(
name: string,
version: string,
chainId: number,
verifyingContract: string,
): Promise<void> {
const expectedHash = signTypedDataUtils.generateDomainHash({
name,
version,
chainId,
verifyingContract,
});
const actualHash = await lib
.externalHashEIP712DomainSeperator(name, version, new BigNumber(chainId), verifyingContract)
.callAsync();
expect(actualHash).to.be.eq(hexUtils.concat(expectedHash));
}
describe('_hashEIP712Domain', async () => {
it('should correctly hash empty input', async () => {
await testHashEIP712DomainAsync('', '', 0, constants.NULL_ADDRESS);
});
it('should correctly hash non-empty input', async () => {
await testHashEIP712DomainAsync('_hashEIP712Domain', '1.0', 62, lib.address);
});
it('should correctly hash non-empty input', async () => {
await testHashEIP712DomainAsync('_hashEIP712Domain', '2.0', 0, lib.address);
});
});
/**
* Tests a specific instance of EIP712 message hashing.
* @param lib The LibEIP712 contract to call.
* @param domainHash The hash of the EIP712 domain of this instance.
* @param hashStruct The hash of the struct of this instance.
*/
async function testHashEIP712MessageAsync(domainHash: string, hashStruct: string): Promise<void> {
// Remove the hex prefix from the domain hash and the hash struct
const unprefixedDomainHash = domainHash.slice(2, domainHash.length);
const unprefixedHashStruct = hashStruct.slice(2, hashStruct.length);
// Hash the provided input to get the expected hash
const input = '0x1901'.concat(unprefixedDomainHash.concat(unprefixedHashStruct));
const expectedHash = hexUtils.hash(input);
// Get the actual hash by calling the smart contract
const actualHash = await lib.externalHashEIP712Message(domainHash, hashStruct).callAsync();
// Verify that the actual hash matches the expected hash
expect(actualHash).to.be.eq(expectedHash);
}
describe('_hashEIP712Message', () => {
it('should correctly hash empty input', async () => {
await testHashEIP712MessageAsync(constants.NULL_BYTES32, constants.NULL_BYTES32);
});
it('should correctly hash non-empty input', async () => {
await testHashEIP712MessageAsync(
'0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6', // keccak256(abi.encode(1))
'0x405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace', // keccak256(abi.encode(2))
);
});
it('should correctly hash non-empty input', async () => {
await testHashEIP712MessageAsync(
'0x405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace', // keccak256(abi.encode(2))
'0xc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b', // keccak256(abi.encode(3))
);
});
});
});

View File

@@ -1,421 +0,0 @@
import {
blockchainTests,
constants,
describe,
expect,
testCombinatoriallyWithReferenceFunc,
uint256Values,
} from '@0x/contracts-test-utils';
import { BigNumber, LibMathRevertErrors, SafeMathRevertErrors } from '@0x/utils';
import {
getPartialAmountCeil,
getPartialAmountFloor,
isRoundingErrorCeil,
isRoundingErrorFloor,
safeGetPartialAmountCeil,
safeGetPartialAmountFloor,
} from '../src/reference_functions';
import { artifacts } from './artifacts';
import { TestLibMathContract } from './wrappers';
blockchainTests('LibMath', env => {
const { ONE_ETHER, MAX_UINT256, MAX_UINT256_ROOT, ZERO_AMOUNT } = constants;
let libsContract: TestLibMathContract;
before(async () => {
libsContract = await TestLibMathContract.deployFrom0xArtifactAsync(
artifacts.TestLibMath,
env.provider,
env.txDefaults,
{},
);
});
// Wrap a reference function with identical arguments in a promise.
function createAsyncReferenceFunction<T>(ref: (...args: any[]) => T): (...args: any[]) => Promise<T> {
return async (...args: any[]): Promise<T> => {
return ref(...args);
};
}
function createContractTestFunction<T>(name: string): (...args: any[]) => Promise<T> {
return async (...args: any[]): Promise<T> => {
return (libsContract as any)[name](...args).callAsync;
};
}
describe('getPartialAmountFloor', () => {
describe.optional('combinatorial tests', () => {
testCombinatoriallyWithReferenceFunc(
'getPartialAmountFloor',
createAsyncReferenceFunction(getPartialAmountFloor),
createContractTestFunction('getPartialAmountFloor'),
[uint256Values, uint256Values, uint256Values],
);
});
describe('explicit tests', () => {
it('matches the reference function output', async () => {
const numerator = ONE_ETHER;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = ONE_ETHER.times(0.01);
const expected = getPartialAmountFloor(numerator, denominator, target);
const actual = await libsContract.getPartialAmountFloor(numerator, denominator, target).callAsync();
expect(actual).to.bignumber.eq(expected);
});
it('rounds down when computing the partial amount', async () => {
const numerator = ONE_ETHER.times(0.6);
const denominator = ONE_ETHER.times(1.8);
const target = ONE_ETHER;
const expected = ONE_ETHER.dividedToIntegerBy(3);
const actual = await libsContract.getPartialAmountFloor(numerator, denominator, target).callAsync();
expect(actual).to.bignumber.eq(expected);
});
it('reverts if `denominator` is zero', async () => {
const numerator = ONE_ETHER;
const denominator = ZERO_AMOUNT;
const target = ONE_ETHER.times(0.01);
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.DivisionByZero,
numerator.times(target),
denominator,
);
return expect(
libsContract.getPartialAmountFloor(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
it('reverts if `numerator * target` overflows', async () => {
const numerator = MAX_UINT256;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = MAX_UINT256_ROOT.times(2);
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
numerator,
target,
);
return expect(
libsContract.getPartialAmountFloor(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
});
});
describe('getPartialAmountCeil', () => {
describe.optional('combinatorial tests', () => {
testCombinatoriallyWithReferenceFunc(
'getPartialAmountCeil',
createAsyncReferenceFunction(getPartialAmountCeil),
createContractTestFunction('getPartialAmountCeil'),
[uint256Values, uint256Values, uint256Values],
);
});
describe('explicit tests', () => {
it('matches the reference function output', async () => {
const numerator = ONE_ETHER;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = ONE_ETHER.times(0.01);
const expected = getPartialAmountCeil(numerator, denominator, target);
const actual = await libsContract.getPartialAmountCeil(numerator, denominator, target).callAsync();
expect(actual).to.bignumber.eq(expected);
});
it('rounds up when computing the partial amount', async () => {
const numerator = ONE_ETHER.times(0.6);
const denominator = ONE_ETHER.times(1.8);
const target = ONE_ETHER;
const expected = ONE_ETHER.dividedToIntegerBy(3).plus(1);
const actual = await libsContract.getPartialAmountCeil(numerator, denominator, target).callAsync();
expect(actual).to.bignumber.eq(expected);
});
it('reverts if `denominator` is zero', async () => {
const numerator = ONE_ETHER;
const denominator = ZERO_AMOUNT;
const target = ONE_ETHER.times(0.01);
// This will actually manifest as a subtraction underflow.
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.SubtractionUnderflow,
denominator,
new BigNumber(1),
);
return expect(
libsContract.getPartialAmountCeil(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
it('reverts if `numerator * target` overflows', async () => {
const numerator = MAX_UINT256;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = MAX_UINT256_ROOT.times(2);
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
numerator,
target,
);
return expect(
libsContract.getPartialAmountCeil(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
});
});
describe('safeGetPartialAmountFloor', () => {
describe.optional('combinatorial tests', () => {
testCombinatoriallyWithReferenceFunc(
'safeGetPartialAmountFloor',
createAsyncReferenceFunction(safeGetPartialAmountFloor),
createContractTestFunction('safeGetPartialAmountFloor'),
[uint256Values, uint256Values, uint256Values],
);
});
describe('explicit tests', () => {
it('matches the reference function output', async () => {
const numerator = ONE_ETHER;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = ONE_ETHER.times(0.01);
const expected = safeGetPartialAmountFloor(numerator, denominator, target);
const actual = await libsContract.safeGetPartialAmountFloor(numerator, denominator, target).callAsync();
expect(actual).to.bignumber.eq(expected);
});
it('rounds down when computing the partial amount', async () => {
const numerator = ONE_ETHER.times(0.6);
const denominator = ONE_ETHER.times(1.8);
const target = ONE_ETHER;
const expected = ONE_ETHER.dividedToIntegerBy(3);
const actual = await libsContract.safeGetPartialAmountFloor(numerator, denominator, target).callAsync();
expect(actual).to.bignumber.eq(expected);
});
it('reverts for a rounding error', async () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(333);
const expectedError = new LibMathRevertErrors.RoundingError(numerator, denominator, target);
return expect(
libsContract.safeGetPartialAmountFloor(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
it('reverts if `denominator` is zero', async () => {
const numerator = ONE_ETHER;
const denominator = ZERO_AMOUNT;
const target = ONE_ETHER.times(0.01);
const expectedError = new LibMathRevertErrors.DivisionByZeroError();
return expect(
libsContract.safeGetPartialAmountFloor(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
it('reverts if `numerator * target` overflows', async () => {
const numerator = MAX_UINT256;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = MAX_UINT256_ROOT.times(2);
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
numerator,
target,
);
return expect(
libsContract.safeGetPartialAmountFloor(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
});
});
describe('safeGetPartialAmountCeil', () => {
describe.optional('combinatorial tests', () => {
testCombinatoriallyWithReferenceFunc(
'safeGetPartialAmountCeil',
createAsyncReferenceFunction(safeGetPartialAmountCeil),
createContractTestFunction('safeGetPartialAmountCeil'),
[uint256Values, uint256Values, uint256Values],
);
});
describe('explicit tests', () => {
it('matches the reference function output', async () => {
const numerator = ONE_ETHER;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = ONE_ETHER.times(0.01);
const expected = safeGetPartialAmountCeil(numerator, denominator, target);
const actual = await libsContract.safeGetPartialAmountCeil(numerator, denominator, target).callAsync();
expect(actual).to.bignumber.eq(expected);
});
it('rounds up when computing the partial amount', async () => {
const numerator = ONE_ETHER.times(0.6);
const denominator = ONE_ETHER.times(1.8);
const target = ONE_ETHER;
const expected = ONE_ETHER.dividedToIntegerBy(3).plus(1);
const actual = await libsContract.safeGetPartialAmountCeil(numerator, denominator, target).callAsync();
expect(actual).to.bignumber.eq(expected);
});
it('reverts for a rounding error', async () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(333);
const expectedError = new LibMathRevertErrors.RoundingError(numerator, denominator, target);
return expect(
libsContract.safeGetPartialAmountCeil(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
it('reverts if `denominator` is zero', async () => {
const numerator = ONE_ETHER;
const denominator = ZERO_AMOUNT;
const target = ONE_ETHER.times(0.01);
const expectedError = new LibMathRevertErrors.DivisionByZeroError();
return expect(
libsContract.safeGetPartialAmountCeil(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
it('reverts if `numerator * target` overflows', async () => {
const numerator = MAX_UINT256;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = MAX_UINT256_ROOT.times(2);
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
numerator,
target,
);
return expect(
libsContract.safeGetPartialAmountCeil(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
});
});
describe('isRoundingErrorFloor', () => {
describe.optional('combinatorial tests', () => {
testCombinatoriallyWithReferenceFunc(
'isRoundingErrorFloor',
createAsyncReferenceFunction(isRoundingErrorFloor),
createContractTestFunction('isRoundingErrorFloor'),
[uint256Values, uint256Values, uint256Values],
);
});
describe('explicit tests', () => {
it('returns true when `numerator * target / denominator` produces an error >= 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(102);
const target = new BigNumber(52);
const actual = await libsContract.isRoundingErrorFloor(numerator, denominator, target).callAsync();
expect(actual).to.eq(true);
});
it('returns false when `numerator * target / denominator` produces an error < 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(101);
const target = new BigNumber(92);
const actual = await libsContract.isRoundingErrorFloor(numerator, denominator, target).callAsync();
expect(actual).to.eq(false);
});
it('matches the reference function output', async () => {
const numerator = ONE_ETHER;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = ONE_ETHER.times(0.01);
const expected = isRoundingErrorFloor(numerator, denominator, target);
const actual = await libsContract.isRoundingErrorFloor(numerator, denominator, target).callAsync();
expect(actual).to.eq(expected);
});
it('reverts if `denominator` is zero', async () => {
const numerator = ONE_ETHER;
const denominator = ZERO_AMOUNT;
const target = ONE_ETHER.times(0.01);
const expectedError = new LibMathRevertErrors.DivisionByZeroError();
return expect(
libsContract.isRoundingErrorFloor(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
it('reverts if `numerator * target` overflows', async () => {
const numerator = MAX_UINT256;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = MAX_UINT256_ROOT.times(2);
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
numerator,
target,
);
return expect(
libsContract.isRoundingErrorFloor(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
});
});
describe('isRoundingErrorCeil', () => {
describe.optional('combinatorial tests', () => {
testCombinatoriallyWithReferenceFunc(
'isRoundingErrorCeil',
createAsyncReferenceFunction(isRoundingErrorCeil),
createContractTestFunction('isRoundingErrorCeil'),
[uint256Values, uint256Values, uint256Values],
);
});
describe('explicit tests', () => {
it('returns true when `numerator * target / (denominator - 1)` produces an error >= 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(101);
const target = new BigNumber(92);
const actual = await libsContract.isRoundingErrorCeil(numerator, denominator, target).callAsync();
expect(actual).to.eq(true);
});
it('returns false when `numerator * target / (denominator - 1)` produces an error < 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(102);
const target = new BigNumber(52);
const actual = await libsContract.isRoundingErrorCeil(numerator, denominator, target).callAsync();
expect(actual).to.eq(false);
});
it('matches the reference function output', async () => {
const numerator = ONE_ETHER;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = ONE_ETHER.times(0.01);
const expected = isRoundingErrorCeil(numerator, denominator, target);
const actual = await libsContract.isRoundingErrorCeil(numerator, denominator, target).callAsync();
expect(actual).to.eq(expected);
});
it('reverts if `denominator` is zero', async () => {
const numerator = ONE_ETHER;
const denominator = ZERO_AMOUNT;
const target = ONE_ETHER.times(0.01);
const expectedError = new LibMathRevertErrors.DivisionByZeroError();
return expect(
libsContract.isRoundingErrorCeil(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
it('reverts if `numerator * target` overflows', async () => {
const numerator = MAX_UINT256;
const denominator = ONE_ETHER.dividedToIntegerBy(2);
const target = MAX_UINT256_ROOT.times(2);
const expectedError = new SafeMathRevertErrors.Uint256BinOpError(
SafeMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
numerator,
target,
);
return expect(
libsContract.isRoundingErrorCeil(numerator, denominator, target).callAsync(),
).to.revertWith(expectedError);
});
});
});
});

View File

@@ -1,98 +0,0 @@
import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import { DecodedLogArgs, LogWithDecodedArgs } from 'ethereum-types';
import { artifacts } from './artifacts';
import { TestLogDecodingContract } from './wrappers';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('TestLogDecoding', () => {
let testLogDecodingWithDependencies: TestLogDecodingContract;
let testLogDecodingDeployedWithoutDependencies: TestLogDecodingContract;
const expectedEvent = {
foo: new BigNumber(256),
bar: '0x1234',
car: '4321',
};
const expectedDownstreamEvent = {
lorem: new BigNumber(256),
ipsum: '4321',
};
const emptyDependencyList = {};
before(async () => {
testLogDecodingDeployedWithoutDependencies = await TestLogDecodingContract.deployFrom0xArtifactAsync(
artifacts.TestLogDecoding,
provider,
txDefaults,
emptyDependencyList,
);
testLogDecodingWithDependencies = await TestLogDecodingContract.deployFrom0xArtifactAsync(
artifacts.TestLogDecoding,
provider,
txDefaults,
artifacts,
);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('Decoding Log Arguments', () => {
it('should decode locally emitted event args when no dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingDeployedWithoutDependencies
.emitEvent()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(1);
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
});
it('should not decode event args when no dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingDeployedWithoutDependencies
.emitEventDownstream()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(1);
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.undefined();
});
it('should decode args for local but not downstream event when no dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingDeployedWithoutDependencies
.emitEventsLocalAndDownstream()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(2);
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
expect((txReceipt.logs[1] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.undefined();
});
it('should decode locally emitted event args when dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingWithDependencies.emitEvent().awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(1);
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
});
it('should decode downstream event args when dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingWithDependencies
.emitEventDownstream()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(1);
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(
expectedDownstreamEvent,
);
});
it('should decode args for both local and downstream events when dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingWithDependencies
.emitEventsLocalAndDownstream()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(2);
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
expect((txReceipt.logs[1] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(
expectedDownstreamEvent,
);
});
});
});

View File

@@ -1,141 +0,0 @@
import { blockchainTests, constants } from '@0x/contracts-test-utils';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import { artifacts } from './artifacts';
import { TestRefundableContract, TestRefundableReceiverContract } from './wrappers';
blockchainTests('Refundable', env => {
let refundable: TestRefundableContract;
let receiver: TestRefundableReceiverContract;
const ONE_HUNDRED = new BigNumber(100);
const ONE_THOUSAND = new BigNumber(1000);
before(async () => {
// Create the refundable contract.
refundable = await TestRefundableContract.deployFrom0xArtifactAsync(
artifacts.TestRefundable,
env.provider,
env.txDefaults,
{},
);
// Create the receiver contract.
receiver = await TestRefundableReceiverContract.deployFrom0xArtifactAsync(
artifacts.TestRefundableReceiver,
env.provider,
env.txDefaults,
{},
);
});
// The contents of these typescript tests is not adequate to understand the assertions that are made during
// these calls. For a more accurate picture, checkout out "./contracts/test/TestRefundableReceiver.sol". Specifically,
// the function `testRefundNonzeroBalance()` is used in this test suite.
blockchainTests.resets('refundNonzeroBalance', () => {
it('should not send a refund when no value is sent', async () => {
// Send 100 wei to the refundable contract that should be refunded.
await receiver.testRefundNonZeroBalance(refundable.address).awaitTransactionSuccessAsync({
value: constants.ZERO_AMOUNT,
});
});
it('should send a full refund when nonzero value is sent', async () => {
// Send 100 wei to the refundable contract that should be refunded.
await receiver.testRefundNonZeroBalance(refundable.address).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
});
});
// The contents of these typescript tests is not adequate to understand the assertions that are made during
// these calls. For a more accurate picture, checkout out "./contracts/test/TestRefundableReceiver.sol".
blockchainTests.resets('refundFinalBalance', () => {
it('should fully refund the sender when `shouldNotRefund` is false', async () => {
// Send 100 wei to the refundable contract that should be refunded to the receiver contract.
await receiver.testRefundFinalBalance(refundable.address, false).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
});
// This test may not be necessary, but it is included here as a sanity check.
it('should fully refund the sender when `shouldNotRefund` is false for two calls in a row', async () => {
// Send 100 wei to the refundable contract that should be refunded to the receiver contract.
await receiver.testRefundFinalBalance(refundable.address, false).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
// Send 1000 wei to the refundable contract that should be refunded to the receiver contract.
await receiver.testRefundFinalBalance(refundable.address, false).awaitTransactionSuccessAsync({
value: new BigNumber(1000),
});
});
it('should not refund the sender if `shouldNotRefund` is true', async () => {
/// Send 100 wei to the refundable contract that should not be refunded.
await receiver.testRefundFinalBalance(refundable.address, true).awaitTransactionSuccessAsync({
value: new BigNumber(1000),
});
});
});
// The contents of these typescript tests is not adequate to understand the assertions that are made during
// these calls. For a more accurate picture, checkout out "./contracts/test/TestRefundableReceiver.sol".
blockchainTests.resets('disableRefundUntilEnd', () => {
it('should fully refund the sender when `shouldNotRefund` is false', async () => {
// Send 100 wei to the refundable contract that should be refunded to the receiver contract.
await receiver.testDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
});
// This test may not be necessary, but it is included here as a sanity check.
it('should fully refund the sender when `shouldNotRefund` is false for two calls in a row', async () => {
// Send 100 wei to the refundable contract that should be refunded to the receiver contract.
await receiver.testDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
// Send 1000 wei to the refundable contract that should be refunded to the receiver contract.
await receiver.testDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
value: ONE_THOUSAND,
});
});
it('should not refund the sender if `shouldNotRefund` is true', async () => {
/// Send 100 wei to the refundable contract that should not be refunded.
await receiver.testDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
});
it('should disable the `disableRefundUntilEnd` modifier and refund when `shouldNotRefund` is false', async () => {
/// Send 100 wei to the refundable contract that should be refunded.
await receiver.testNestedDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
});
it('should disable the `refundFinalBalance` modifier and send no refund when `shouldNotRefund` is true', async () => {
/// Send 100 wei to the refundable contract that should not be refunded.
await receiver.testNestedDisableRefundUntilEnd(refundable.address, true).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
});
it('should disable the `refundFinalBalance` modifier and refund when `shouldNotRefund` is false', async () => {
/// Send 100 wei to the refundable contract that should be refunded.
await receiver.testMixedRefunds(refundable.address, false).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
});
it('should disable the `refundFinalBalance` modifier and send no refund when `shouldNotRefund` is true', async () => {
/// Send 100 wei to the refundable contract that should not be refunded.
await receiver.testMixedRefunds(refundable.address, true).awaitTransactionSuccessAsync({
value: ONE_HUNDRED,
});
});
});
});

View File

@@ -3,21 +3,13 @@
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
* -----------------------------------------------------------------------------
*/
export * from '../test/generated-wrappers/authorizable';
export * from '../test/generated-wrappers/authorizable_v06';
export * from '../test/generated-wrappers/authorizable_v08';
export * from '../test/generated-wrappers/d18';
export * from '../test/generated-wrappers/deployment_constants';
export * from '../test/generated-wrappers/i_authorizable';
export * from '../test/generated-wrappers/i_authorizable_v06';
export * from '../test/generated-wrappers/i_authorizable_v08';
export * from '../test/generated-wrappers/i_ownable';
export * from '../test/generated-wrappers/i_ownable_v06';
export * from '../test/generated-wrappers/i_ownable_v08';
export * from '../test/generated-wrappers/lib_address';
export * from '../test/generated-wrappers/lib_address_array';
export * from '../test/generated-wrappers/lib_address_array_rich_errors';
export * from '../test/generated-wrappers/lib_authorizable_rich_errors';
export * from '../test/generated-wrappers/lib_authorizable_rich_errors_v06';
export * from '../test/generated-wrappers/lib_authorizable_rich_errors_v08';
export * from '../test/generated-wrappers/lib_bytes';
@@ -26,11 +18,6 @@ export * from '../test/generated-wrappers/lib_bytes_rich_errors_v06';
export * from '../test/generated-wrappers/lib_bytes_rich_errors_v08';
export * from '../test/generated-wrappers/lib_bytes_v06';
export * from '../test/generated-wrappers/lib_bytes_v08';
export * from '../test/generated-wrappers/lib_e_i_p1271';
export * from '../test/generated-wrappers/lib_e_i_p712';
export * from '../test/generated-wrappers/lib_fractions';
export * from '../test/generated-wrappers/lib_math';
export * from '../test/generated-wrappers/lib_math_rich_errors';
export * from '../test/generated-wrappers/lib_math_rich_errors_v06';
export * from '../test/generated-wrappers/lib_math_rich_errors_v08';
export * from '../test/generated-wrappers/lib_math_v06';
@@ -53,20 +40,9 @@ export * from '../test/generated-wrappers/ownable';
export * from '../test/generated-wrappers/ownable_v06';
export * from '../test/generated-wrappers/ownable_v08';
export * from '../test/generated-wrappers/reentrancy_guard';
export * from '../test/generated-wrappers/reentrancy_guard_v06';
export * from '../test/generated-wrappers/reentrancy_guard_v08';
export * from '../test/generated-wrappers/refundable';
export * from '../test/generated-wrappers/test_authorizable';
export * from '../test/generated-wrappers/test_lib_address';
export * from '../test/generated-wrappers/test_lib_address_array';
export * from '../test/generated-wrappers/test_lib_bytes';
export * from '../test/generated-wrappers/test_lib_e_i_p712';
export * from '../test/generated-wrappers/test_lib_math';
export * from '../test/generated-wrappers/test_lib_rich_errors';
export * from '../test/generated-wrappers/test_lib_safe_math';
export * from '../test/generated-wrappers/test_log_decoding';
export * from '../test/generated-wrappers/test_log_decoding_downstream';
export * from '../test/generated-wrappers/test_ownable';
export * from '../test/generated-wrappers/test_reentrancy_guard';
export * from '../test/generated-wrappers/test_refundable';
export * from '../test/generated-wrappers/test_refundable_receiver';