temp
This commit is contained in:
@@ -19,5 +19,5 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"contracts": ["TEC", "TestLibs"]
|
||||
"contracts": ["TEC", "TestLibs", "TestInternals"]
|
||||
}
|
||||
|
||||
@@ -18,11 +18,13 @@
|
||||
|
||||
pragma solidity ^0.5.3;
|
||||
|
||||
import "@0x/contract-utils/contracts/src/LibBytes.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||
import "./mixins/MSignatureValidator.sol";
|
||||
|
||||
|
||||
contract MixinSignatureValidator {
|
||||
|
||||
contract MixinSignatureValidator is
|
||||
MSignatureValidator
|
||||
{
|
||||
using LibBytes for bytes;
|
||||
|
||||
/// @dev Recovers the address of a signer given a hash and signature.
|
||||
|
||||
@@ -173,7 +173,7 @@ contract MixinTECApprovalVerifier is
|
||||
|
||||
// Hash approval message and recover signer address
|
||||
bytes32 approvalHash = getTECApprovalHash(approval);
|
||||
address approvalSignerAddress = getAddressFromSignature(approvalHash, approvalSignature);
|
||||
address approvalSignerAddress = getSignerAddress(approvalHash, approvalSignature);
|
||||
|
||||
// Revert if signer of approval is not the feeRecipient of order
|
||||
require(
|
||||
@@ -220,7 +220,7 @@ contract MixinTECApprovalVerifier is
|
||||
|
||||
// Hash approval message and recover signer address
|
||||
bytes32 approvalHash = getTECApprovalHash(approval);
|
||||
address approvalSignerAddress = getAddressFromSignature(approvalHash, approvalSignatures[i]);
|
||||
address approvalSignerAddress = getSignerAddress(approvalHash, approvalSignatures[i]);
|
||||
|
||||
// Add approval signer to list of signers
|
||||
approvalSignerAddresses.append(approvalSignerAddress);
|
||||
|
||||
@@ -20,6 +20,7 @@ pragma solidity 0.5.3;
|
||||
pragma experimental "ABIEncoderV2";
|
||||
|
||||
import "./libs/LibConstants.sol";
|
||||
import "./MixinSignatureValidator.sol";
|
||||
import "./MixinTECApprovalVerifier.sol";
|
||||
import "./MixinTECCore.sol";
|
||||
|
||||
@@ -27,6 +28,7 @@ import "./MixinTECCore.sol";
|
||||
// solhint-disable no-empty-blocks
|
||||
contract TEC is
|
||||
LibConstants,
|
||||
MixinSignatureValidator,
|
||||
MixinTECApprovalVerifier,
|
||||
MixinTECCore
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ contract MSignatureValidator {
|
||||
/// @dev Recovers the address of a signer given a hash and signature.
|
||||
/// @param hash Any 32 byte hash.
|
||||
/// @param signature Proof that the hash has been signed by signer.
|
||||
function getAddressFromSignature(bytes32 hash, bytes memory signature)
|
||||
function getSignerAddress(bytes32 hash, bytes memory signature)
|
||||
internal
|
||||
pure
|
||||
returns (address signerAddress);
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
|
||||
},
|
||||
"config": {
|
||||
"abis": "generated-artifacts/@(TEC|TestLibs).json"
|
||||
"abis": "generated-artifacts/@(TEC|TestLibs|TestInternals).json"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { ContractArtifact } from 'ethereum-types';
|
||||
|
||||
import * as TEC from '../../generated-artifacts/TEC.json';
|
||||
import * as TestInternals from '../../generated-artifacts/TestInternals.json';
|
||||
import * as TestLibs from '../../generated-artifacts/TestLibs.json';
|
||||
|
||||
export const artifacts = {
|
||||
TEC: TEC as ContractArtifact,
|
||||
TestLibs: TestLibs as ContractArtifact,
|
||||
TestInternals: TestInternals as ContractArtifact,
|
||||
};
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from '../../generated-wrappers/tec';
|
||||
export * from '../../generated-wrappers/test_libs';
|
||||
export * from '../../generated-wrappers/test_internals';
|
||||
|
||||
56
contracts/tec/test/internals.ts
Normal file
56
contracts/tec/test/internals.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { chaiSetup, constants, provider, TransactionFactory, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { transactionHashUtils } from '@0x/order-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
|
||||
import { artifacts, TestInternalsContract } from '../src';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('Internals tests', () => {
|
||||
let transactionSignerAddress: string;
|
||||
let approvalSignerAddress: string;
|
||||
let testInternals: TestInternalsContract;
|
||||
let transactionFactory: TransactionFactory;
|
||||
|
||||
before(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
after(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
testInternals = await TestInternalsContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestInternals,
|
||||
provider,
|
||||
txDefaults,
|
||||
);
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
[transactionSignerAddress, approvalSignerAddress] = accounts.slice(0, 2);
|
||||
const transactionSignerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[0];
|
||||
const approvalSignerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[1];
|
||||
transactionFactory = new TransactionFactory(transactionSignerPrivateKey, testInternals.address);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
afterEach(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
|
||||
describe('getSignerAddress', () => {
|
||||
it('should return the correct address', async () => {
|
||||
const data = constants.NULL_BYTES;
|
||||
const transaction = transactionFactory.newSignedTransaction(data);
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
const signerAddress = await testInternals.publicGetSignerAddress.callAsync(
|
||||
transactionHash,
|
||||
transaction.signature,
|
||||
);
|
||||
expect(transaction.signerAddress).to.eq(signerAddress);
|
||||
});
|
||||
});
|
||||
});
|
||||
41
contracts/tec/test/tec.ts
Normal file
41
contracts/tec/test/tec.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
|
||||
import { ExchangeContract } from '@0x/contracts-exchange';
|
||||
import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { TECContract } from '../src';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('TEC tests', () => {
|
||||
let makerAddress: string;
|
||||
let owner: string;
|
||||
let takerAddress: string;
|
||||
let feeRecipientAddress: string;
|
||||
|
||||
// let erc20Proxy: ERC20ProxyContract;
|
||||
|
||||
let erc20Wrapper: ERC20Wrapper;
|
||||
before(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
after(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = _.slice(accounts, 0, 4));
|
||||
|
||||
erc20Wrapper = new ERC20Wrapper(provider, usedAddresses, owner);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
afterEach(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
});
|
||||
0
contracts/tec/test/utils/approval_factory.ts
Normal file
0
contracts/tec/test/utils/approval_factory.ts
Normal file
12
contracts/tec/test/utils/constants.ts
Normal file
12
contracts/tec/test/utils/constants.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const constants = {
|
||||
TEC_DOMAIN_NAME: '0x Protocol Trade Execution Coordinator',
|
||||
TEC_DOMAIN_VERSION: '1.0.0',
|
||||
TEC_APPROVAL_SCHEMA: {
|
||||
name: 'TECApproval',
|
||||
parameters: [
|
||||
{ name: 'transactionHash', type: 'bytes32' },
|
||||
{ name: 'transactionSignature', type: 'bytes' },
|
||||
{ name: 'approvalExpirationTimeSeconds', type: 'uint256' },
|
||||
],
|
||||
},
|
||||
};
|
||||
7
contracts/tec/test/utils/types.ts
Normal file
7
contracts/tec/test/utils/types.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
export interface TECApproval {
|
||||
transactionHash: string;
|
||||
transactionSignature: string;
|
||||
approvalExpirationTimeSeconds: BigNumber;
|
||||
}
|
||||
@@ -6,6 +6,10 @@
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"],
|
||||
"files": ["./generated-artifacts/TEC.json", "./generated-artifacts/TestLibs.json"],
|
||||
"files": [
|
||||
"./generated-artifacts/TEC.json",
|
||||
"./generated-artifacts/TestLibs.json",
|
||||
"./generated-artifacts/TestInternals.json"
|
||||
],
|
||||
"exclude": ["./deploy/solc/solc_bin"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user