@0x:contracts-exchange Added unit tests for getCurrentContextAddress
This commit is contained in:
committed by
Amir Bandeali
parent
4f1525fe27
commit
74b9ad5536
47
contracts/exchange/contracts/test/TestTransactions.sol
Normal file
47
contracts/exchange/contracts/test/TestTransactions.sol
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.5.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../src/Exchange.sol";
|
||||
import "../src/MixinTransactions.sol";
|
||||
|
||||
|
||||
contract TestTransactions is
|
||||
Exchange
|
||||
{
|
||||
constructor ()
|
||||
public
|
||||
Exchange(1337)
|
||||
{} // solhint-disable-line no-empty-blocks
|
||||
|
||||
function setCurrentContextAddress(address context)
|
||||
external
|
||||
{
|
||||
currentContextAddress = context;
|
||||
}
|
||||
|
||||
function getCurrentContextAddress()
|
||||
external
|
||||
view
|
||||
returns (address)
|
||||
{
|
||||
return _getCurrentContextAddress();
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@
|
||||
"compile:truffle": "truffle compile"
|
||||
},
|
||||
"config": {
|
||||
"abis": "./generated-artifacts/@(Exchange|ExchangeWrapper|IAssetProxy|IAssetProxyDispatcher|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|ISignatureValidator|ITransactions|ITransferSimulator|IWallet|IWrapperFunctions|IsolatedExchange|LibExchangeRichErrorDecoder|MixinAssetProxyDispatcher|MixinExchangeCore|MixinMatchOrders|MixinSignatureValidator|MixinTransactions|MixinTransferSimulator|MixinWrapperFunctions|ReentrancyTester|TestAssetProxyDispatcher|TestExchangeInternals|TestLibExchangeRichErrorDecoder|TestSignatureValidator|TestValidatorWallet|TestWrapperFunctions|Whitelist).json",
|
||||
"abis": "./generated-artifacts/@(Exchange|ExchangeWrapper|IAssetProxy|IAssetProxyDispatcher|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|ISignatureValidator|ITransactions|ITransferSimulator|IWallet|IWrapperFunctions|IsolatedExchange|LibExchangeRichErrorDecoder|MixinAssetProxyDispatcher|MixinExchangeCore|MixinMatchOrders|MixinSignatureValidator|MixinTransactions|MixinTransferSimulator|MixinWrapperFunctions|ReentrancyTester|TestAssetProxyDispatcher|TestExchangeInternals|TestLibExchangeRichErrorDecoder|TestSignatureValidator|TestTransactions|TestValidatorWallet|TestWrapperFunctions|Whitelist).json",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||
},
|
||||
"repository": {
|
||||
|
||||
@@ -32,6 +32,7 @@ import * as TestAssetProxyDispatcher from '../generated-artifacts/TestAssetProxy
|
||||
import * as TestExchangeInternals from '../generated-artifacts/TestExchangeInternals.json';
|
||||
import * as TestLibExchangeRichErrorDecoder from '../generated-artifacts/TestLibExchangeRichErrorDecoder.json';
|
||||
import * as TestSignatureValidator from '../generated-artifacts/TestSignatureValidator.json';
|
||||
import * as TestTransactions from '../generated-artifacts/TestTransactions.json';
|
||||
import * as TestValidatorWallet from '../generated-artifacts/TestValidatorWallet.json';
|
||||
import * as TestWrapperFunctions from '../generated-artifacts/TestWrapperFunctions.json';
|
||||
import * as Whitelist from '../generated-artifacts/Whitelist.json';
|
||||
@@ -64,6 +65,7 @@ export const artifacts = {
|
||||
TestExchangeInternals: TestExchangeInternals as ContractArtifact,
|
||||
TestLibExchangeRichErrorDecoder: TestLibExchangeRichErrorDecoder as ContractArtifact,
|
||||
TestSignatureValidator: TestSignatureValidator as ContractArtifact,
|
||||
TestTransactions: TestTransactions as ContractArtifact,
|
||||
TestValidatorWallet: TestValidatorWallet as ContractArtifact,
|
||||
TestWrapperFunctions: TestWrapperFunctions as ContractArtifact,
|
||||
};
|
||||
|
||||
@@ -30,6 +30,7 @@ export * from '../generated-wrappers/test_asset_proxy_dispatcher';
|
||||
export * from '../generated-wrappers/test_exchange_internals';
|
||||
export * from '../generated-wrappers/test_lib_exchange_rich_error_decoder';
|
||||
export * from '../generated-wrappers/test_signature_validator';
|
||||
export * from '../generated-wrappers/test_transactions';
|
||||
export * from '../generated-wrappers/test_validator_wallet';
|
||||
export * from '../generated-wrappers/test_wrapper_functions';
|
||||
export * from '../generated-wrappers/whitelist';
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
ExchangeTransactionExecutionEventArgs,
|
||||
ExchangeWrapper,
|
||||
ExchangeWrapperContract,
|
||||
TestTransactionsContract,
|
||||
WhitelistContract,
|
||||
} from '../src/';
|
||||
|
||||
@@ -52,6 +53,7 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
let feeRecipientAddress: string;
|
||||
let validatorAddress: string;
|
||||
let taker2Address: string;
|
||||
let transactionsContract: TestTransactionsContract;
|
||||
|
||||
let erc20TokenA: DummyERC20TokenContract;
|
||||
let erc20TokenB: DummyERC20TokenContract;
|
||||
@@ -138,6 +140,13 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchangeInstance.address, chainId);
|
||||
takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchangeInstance.address, chainId);
|
||||
taker2TransactionFactory = new TransactionFactory(taker2PrivateKey, exchangeInstance.address, chainId);
|
||||
|
||||
transactionsContract = await TestTransactionsContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestTransactions,
|
||||
env.provider,
|
||||
env.txDefaults,
|
||||
{},
|
||||
);
|
||||
});
|
||||
describe('executeTransaction', () => {
|
||||
describe('general functionality', () => {
|
||||
@@ -1189,4 +1198,25 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('getCurrentContext', () => {
|
||||
it('should return the sender address when there is not a saved context address', async () => {
|
||||
const currentContextAddress = await transactionsContract.getCurrentContextAddress.callAsync({
|
||||
from: makerAddress,
|
||||
});
|
||||
expect(currentContextAddress).to.be.eq(makerAddress);
|
||||
});
|
||||
|
||||
it('should return the sender address when there is a saved context address', async () => {
|
||||
// Set the current context address to the taker address
|
||||
await transactionsContract.setCurrentContextAddress.sendTransactionAsync(takerAddress, {
|
||||
from: makerAddress,
|
||||
});
|
||||
|
||||
// Ensure that the queried current context address is the same as the address that was set.
|
||||
const currentContextAddress = await transactionsContract.getCurrentContextAddress.callAsync({
|
||||
from: makerAddress,
|
||||
});
|
||||
expect(currentContextAddress).to.be.eq(takerAddress);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
43
contracts/exchange/test/transactions_unit_tests.ts
Normal file
43
contracts/exchange/test/transactions_unit_tests.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { blockchainTests, chaiSetup, describe } from '@0x/contracts-test-utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { artifacts, TestTransactionsContract } from '../src';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
blockchainTests.resets('FillOrder Tests', ({ provider, web3Wrapper, txDefaults }) => {
|
||||
let transactionsContract: TestTransactionsContract;
|
||||
let accounts: string[];
|
||||
|
||||
before(async () => {
|
||||
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
|
||||
transactionsContract = await TestTransactionsContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestTransactions,
|
||||
provider,
|
||||
txDefaults,
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
describe('getCurrentContext', () => {
|
||||
it('should return the sender address when there is not a saved context address', async () => {
|
||||
const currentContextAddress = await transactionsContract.getCurrentContextAddress.callAsync({
|
||||
from: accounts[0],
|
||||
});
|
||||
expect(currentContextAddress).to.be.eq(accounts[0]);
|
||||
});
|
||||
|
||||
it('should return the sender address when there is a saved context address', async () => {
|
||||
// Set the current context address to the taker address
|
||||
await transactionsContract.setCurrentContextAddress.sendTransactionAsync(accounts[1]);
|
||||
|
||||
// Ensure that the queried current context address is the same as the address that was set.
|
||||
const currentContextAddress = await transactionsContract.getCurrentContextAddress.callAsync({
|
||||
from: accounts[0],
|
||||
});
|
||||
expect(currentContextAddress).to.be.eq(accounts[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -30,6 +30,7 @@
|
||||
"generated-artifacts/TestExchangeInternals.json",
|
||||
"generated-artifacts/TestLibExchangeRichErrorDecoder.json",
|
||||
"generated-artifacts/TestSignatureValidator.json",
|
||||
"generated-artifacts/TestTransactions.json",
|
||||
"generated-artifacts/TestValidatorWallet.json",
|
||||
"generated-artifacts/TestWrapperFunctions.json",
|
||||
"generated-artifacts/Whitelist.json"
|
||||
|
||||
Reference in New Issue
Block a user