Fix coverage (#606)
This commit is contained in:
parent
004d466a3d
commit
37177d30f7
|
@ -1,3 +1,4 @@
|
|||
node_modules
|
||||
deploy
|
||||
upgrade
|
||||
coverage
|
||||
|
|
|
@ -53,7 +53,7 @@ jobs:
|
|||
CC_SECRET: ${{ secrets.CC_SECRET }}
|
||||
coverage:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags')
|
||||
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags') || contains(github.event.head_commit.message, 'coverage')
|
||||
steps:
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
|
|
|
@ -4,6 +4,7 @@ flats
|
|||
.node*
|
||||
.idea
|
||||
coverage
|
||||
coverage.json
|
||||
*.sublime-*
|
||||
.0x-artifacts
|
||||
deploy/*.config
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
const Web3 = require('web3')
|
||||
|
||||
async function waitCompoundDeploy(config) {
|
||||
const web3 = new Web3(config.provider)
|
||||
const abi = [{
|
||||
inputs: [{ name: "", type: "address"}],
|
||||
outputs: [{ name: "", type: "uint256" }],
|
||||
name: "balanceOf",
|
||||
stateMutability: "view",
|
||||
type: "function"
|
||||
}]
|
||||
const cDai = new web3.eth.Contract(abi, '0x615cba17EE82De39162BB87dBA9BcfD6E8BcF298')
|
||||
const faucet = (await web3.eth.getAccounts())[6]
|
||||
while (true) {
|
||||
try {
|
||||
if (await cDai.methods.balanceOf(faucet).call() !== '0') break
|
||||
} catch (e) {
|
||||
await new Promise(res => setTimeout(res, 1000))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
skipFiles: [
|
||||
'Migrations.sol',
|
||||
'mocks',
|
||||
'interfaces',
|
||||
'helpers'
|
||||
],
|
||||
providerOptions: {
|
||||
port: 8545,
|
||||
_chainId: 1337,
|
||||
network_id: 1337,
|
||||
seed: 'TestRPC is awesome!',
|
||||
default_balance_ether: 1000000
|
||||
},
|
||||
onServerReady: waitCompoundDeploy,
|
||||
istanbulReporter: ['lcov']
|
||||
}
|
|
@ -4,7 +4,7 @@ pragma experimental ABIEncoderV2;
|
|||
|
||||
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
|
||||
import "../BasePaymaster.sol";
|
||||
import "./IUniswapRouter02.sol";
|
||||
import "./IUniswapV2Router02.sol";
|
||||
import "../../upgradeable_contracts/GSNForeignERC20Bridge.sol";
|
||||
|
||||
contract TokenPaymaster is BasePaymaster {
|
||||
|
|
|
@ -9,7 +9,7 @@ import "../upgradeable_contracts/arbitrary_message/ForeignAMBWithGasToken.sol";
|
|||
contract ForeignAMBWithGasTokenMock is ForeignAMBWithGasToken {
|
||||
function gasToken() public pure returns (IGasToken) {
|
||||
// Address generated in unit test, also hardcoded in GasTokenMock
|
||||
return IGasToken(0x5b1869D9A4C187F2EAa108f3062412ecf0526b24);
|
||||
return IGasToken(0x64830eD3d58194d5b3Bc1BEa19F1ce9666AC0602);
|
||||
}
|
||||
|
||||
function collectGasTokens() external {
|
||||
|
|
|
@ -10,6 +10,7 @@ contract UniswapRouterMock {
|
|||
}
|
||||
|
||||
function getAmountsOut(uint256 amountIn, address[] path) external pure returns (uint256[] memory amounts) {
|
||||
(path);
|
||||
amounts = new uint256[](2);
|
||||
amounts[0] = amountIn;
|
||||
amounts[1] = amountIn / 100;
|
||||
|
@ -20,6 +21,7 @@ contract UniswapRouterMock {
|
|||
external
|
||||
returns (uint256[] memory amounts)
|
||||
{
|
||||
(amountInMax, path, to, deadline);
|
||||
uint256 ethToSend = amountOut;
|
||||
uint256 tokensToTake = ethToSend * 100;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,8 +20,6 @@
|
|||
"author": "POA network",
|
||||
"license": "GPLv3",
|
||||
"dependencies": {
|
||||
"@0x/sol-coverage": "^4.0.10",
|
||||
"@0x/sol-trace": "^3.0.10",
|
||||
"@opengsn/gsn": "^2.1.0",
|
||||
"array-flat-polyfill": "^1.0.1",
|
||||
"openzeppelin-solidity": "1.12.0",
|
||||
|
@ -43,11 +41,11 @@
|
|||
"eth-gas-reporter": "^0.2.11",
|
||||
"ethereumjs-abi": "0.6.8",
|
||||
"ethereumjs-util": "5.2.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"nodemon": "^1.17.3",
|
||||
"prettier": "^1.18.2",
|
||||
"prettier-plugin-solidity": "1.0.0-alpha.32",
|
||||
"solhint": "2.2.0",
|
||||
"solhint-plugin-prettier": "0.0.3"
|
||||
"solhint-plugin-prettier": "0.0.3",
|
||||
"solidity-coverage": "0.7.16"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ contract('ForeignAMB', async accounts => {
|
|||
|
||||
before(async () => {
|
||||
validatorContract = await BridgeValidators.new()
|
||||
gasTokenContract = await GasToken.new()
|
||||
gasTokenContract = await GasToken.new({ from: accounts[7] })
|
||||
authorities = [accounts[1], accounts[2]]
|
||||
owner = accounts[0]
|
||||
await validatorContract.initialize(1, authorities, owner)
|
||||
|
@ -304,9 +304,7 @@ contract('ForeignAMB', async accounts => {
|
|||
bridgeId = web3.utils.soliditySha3(paddedChainId + foreignBridge.address.slice(2)).slice(10, 50)
|
||||
})
|
||||
it('call requireToPassMessage(address, bytes, uint256)', async () => {
|
||||
const tx = await foreignBridge.methods[
|
||||
'requireToPassMessage(address,bytes,uint256)'
|
||||
](
|
||||
const tx = await foreignBridge.methods['requireToPassMessage(address,bytes,uint256)'](
|
||||
'0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955',
|
||||
'0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03',
|
||||
1535604485,
|
||||
|
|
|
@ -281,9 +281,7 @@ contract('HomeAMB', async accounts => {
|
|||
bridgeId = web3.utils.soliditySha3(paddedChainId + homeBridge.address.slice(2)).slice(10, 50)
|
||||
})
|
||||
it('call requireToPassMessage(address, bytes, uint256)', async () => {
|
||||
const tx = await homeBridge.methods[
|
||||
'requireToPassMessage(address,bytes,uint256)'
|
||||
](
|
||||
const tx = await homeBridge.methods['requireToPassMessage(address,bytes,uint256)'](
|
||||
'0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955',
|
||||
'0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03',
|
||||
1535604485,
|
||||
|
@ -310,9 +308,7 @@ contract('HomeAMB', async accounts => {
|
|||
})
|
||||
it('call requireToPassMessage(address, bytes, uint256) should fail', async () => {
|
||||
// Should fail because gas < minimumGasUsage
|
||||
await homeBridge.methods[
|
||||
'requireToPassMessage(address,bytes,uint256)'
|
||||
](
|
||||
await homeBridge.methods['requireToPassMessage(address,bytes,uint256)'](
|
||||
'0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955',
|
||||
'0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03',
|
||||
10,
|
||||
|
@ -320,9 +316,7 @@ contract('HomeAMB', async accounts => {
|
|||
).should.be.rejectedWith(ERROR_MSG)
|
||||
|
||||
// Should fail because gas > maxGasPerTx
|
||||
await homeBridge.methods[
|
||||
'requireToPassMessage(address,bytes,uint256)'
|
||||
](
|
||||
await homeBridge.methods['requireToPassMessage(address,bytes,uint256)'](
|
||||
'0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955',
|
||||
'0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03',
|
||||
twoEther,
|
||||
|
@ -333,9 +327,7 @@ contract('HomeAMB', async accounts => {
|
|||
expect(await homeBridge.maxGasPerTx()).to.be.bignumber.equal(ZERO)
|
||||
|
||||
// Should fail because maxGasPerTx = 0 so gas > maxGasPerTx
|
||||
await homeBridge.methods[
|
||||
'requireToPassMessage(address,bytes,uint256)'
|
||||
](
|
||||
await homeBridge.methods['requireToPassMessage(address,bytes,uint256)'](
|
||||
'0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955',
|
||||
'0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03',
|
||||
oneEther,
|
||||
|
@ -345,9 +337,7 @@ contract('HomeAMB', async accounts => {
|
|||
await homeBridge.setMaxGasPerTx(oneEther).should.be.fulfilled
|
||||
expect(await homeBridge.maxGasPerTx()).to.be.bignumber.equal(oneEther)
|
||||
|
||||
await homeBridge.methods[
|
||||
'requireToPassMessage(address,bytes,uint256)'
|
||||
](
|
||||
await homeBridge.methods['requireToPassMessage(address,bytes,uint256)'](
|
||||
'0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955',
|
||||
'0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03',
|
||||
oneEther,
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
after(async () => {
|
||||
if (process.env.SOLIDITY_COVERAGE === 'true') {
|
||||
await global.coverageSubprovider.writeCoverageAsync()
|
||||
}
|
||||
})
|
|
@ -2,7 +2,12 @@ version: '3.8'
|
|||
services:
|
||||
ganache:
|
||||
image: trufflesuite/ganache-cli
|
||||
command: --deterministic --gasLimit 20000000 --allowUnlimitedContractSize --chainId 1337
|
||||
command: >
|
||||
--deterministic
|
||||
--gasLimit 20000000
|
||||
--allowUnlimitedContractSize
|
||||
--networkId 1337
|
||||
--chainId 1337
|
||||
ports:
|
||||
- 8545:8545
|
||||
compound:
|
||||
|
@ -10,3 +15,7 @@ services:
|
|||
# build: compound
|
||||
stdin_open: true
|
||||
tty: true
|
||||
environment:
|
||||
- PROVIDER
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
|
|
|
@ -13,7 +13,7 @@ const TokenPaymaster = artifacts.require('TokenPaymaster.sol')
|
|||
const { RelayProvider } = require('@opengsn/gsn')
|
||||
const { GsnTestEnvironment } = require('@opengsn/gsn/dist/GsnTestEnvironment')
|
||||
|
||||
const { toBN, ERROR_MSG } = require('../setup')
|
||||
const { toBN, ERROR_MSG, ZERO_ADDRESS } = require('../setup')
|
||||
const {
|
||||
createMessage,
|
||||
sign,
|
||||
|
@ -47,6 +47,7 @@ contract('ForeignBridge_ERC20_to_Native_GSN', async accounts => {
|
|||
let authorities
|
||||
let owner
|
||||
let token
|
||||
let foreignBridge
|
||||
let otherSideBridge
|
||||
|
||||
let router
|
||||
|
@ -55,7 +56,7 @@ contract('ForeignBridge_ERC20_to_Native_GSN', async accounts => {
|
|||
let ForwarderAddress
|
||||
before(async () => {
|
||||
// Deploy GSN
|
||||
const env = await GsnTestEnvironment.startGsn('localhost')
|
||||
const env = await GsnTestEnvironment.startGsn(web3.currentProvider.host)
|
||||
RelayHubAddress = env.contractsDeployment.relayHubAddress
|
||||
ForwarderAddress = env.contractsDeployment.forwarderAddress
|
||||
|
||||
|
@ -69,11 +70,33 @@ contract('ForeignBridge_ERC20_to_Native_GSN', async accounts => {
|
|||
after(async () => {
|
||||
await GsnTestEnvironment.stopGsn()
|
||||
})
|
||||
describe('#initialize', async () => {
|
||||
it('should initialize', async () => {
|
||||
token = await ERC677BridgeToken.new('Some ERC20', 'RSZT', 18)
|
||||
router = await UniswapRouterMock.new()
|
||||
foreignBridge = await ForeignBridgeErcToNativeMock.new()
|
||||
|
||||
paymaster = await TokenPaymaster.new(
|
||||
RelayHubAddress,
|
||||
ForwarderAddress,
|
||||
ZERO_ADDRESS,
|
||||
router.address,
|
||||
ZERO_ADDRESS,
|
||||
{ from: owner }
|
||||
)
|
||||
|
||||
await paymaster.setToken(token.address, { from: accounts[1] }).should.be.rejected
|
||||
|
||||
await paymaster.setToken(token.address, { from: owner }).should.be.fulfilled
|
||||
await paymaster.setRouter(router.address, { from: owner }).should.be.fulfilled
|
||||
await paymaster.setBridge(foreignBridge.address, { from: owner }).should.be.fulfilled
|
||||
})
|
||||
})
|
||||
|
||||
describe('#executeSignaturesGSN', async () => {
|
||||
const BRIDGE_TOKENS = ether('300')
|
||||
const REQUESTED_TOKENS = BRIDGE_TOKENS
|
||||
|
||||
let foreignBridge
|
||||
let GSNRelayer
|
||||
let GSNSigner
|
||||
beforeEach(async () => {
|
||||
|
@ -165,11 +188,11 @@ contract('ForeignBridge_ERC20_to_Native_GSN', async accounts => {
|
|||
gas: GSNGasLimit
|
||||
})
|
||||
},
|
||||
async () => token.balanceOf(recipientAccount),
|
||||
async () => toBN(await web3.eth.getBalance(recipientAccount)),
|
||||
async () => token.balanceOf(foreignBridge.address),
|
||||
async () => token.balanceOf(paymaster.address),
|
||||
async () => paymaster.getRelayHubDeposit()
|
||||
() => token.balanceOf(recipientAccount),
|
||||
() => web3.eth.getBalance(recipientAccount).then(toBN),
|
||||
() => token.balanceOf(foreignBridge.address),
|
||||
() => token.balanceOf(paymaster.address),
|
||||
() => paymaster.getRelayHubDeposit()
|
||||
)
|
||||
|
||||
userEthBalanceBefore.should.be.bignumber.equal(ZERO)
|
||||
|
|
34
test/test.sh
34
test/test.sh
|
@ -15,18 +15,28 @@ ganache_running() {
|
|||
nc -z localhost 8545
|
||||
}
|
||||
|
||||
if ganache_running; then
|
||||
echo "Using existing ganache instance"
|
||||
else
|
||||
echo "Starting our own ganache instance"
|
||||
docker-compose -f test/docker-compose.yml up -d ganache
|
||||
sleep 5
|
||||
echo "Deploy Compound protocol contracts"
|
||||
docker-compose -f test/docker-compose.yml up compound || true
|
||||
fi
|
||||
|
||||
if [ "$SOLIDITY_COVERAGE" = true ]; then
|
||||
node --max-old-space-size=4096 node_modules/.bin/truffle test 2>/dev/null; istanbul report lcov
|
||||
node --max-old-space-size=4096 node_modules/.bin/truffle run coverage --network ganache 2>/dev/null &
|
||||
pid=$!
|
||||
|
||||
echo "Waiting in-process ganache to launch on port 8545"
|
||||
while ! ganache_running; do
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
echo "Deploy Compound protocol contracts"
|
||||
PROVIDER=http://host.docker.internal:8545 docker-compose -f test/docker-compose.yml up compound || true
|
||||
|
||||
wait $pid
|
||||
else
|
||||
if ganache_running; then
|
||||
echo "Using existing ganache instance"
|
||||
else
|
||||
echo "Starting our own ganache instance"
|
||||
docker-compose -f test/docker-compose.yml up -d ganache
|
||||
sleep 5
|
||||
echo "Deploy Compound protocol contracts"
|
||||
PROVIDER=http://ganache:8545 docker-compose -f test/docker-compose.yml up compound || true
|
||||
fi
|
||||
node_modules/.bin/truffle test --network ganache "$@"
|
||||
fi
|
||||
fi
|
|
@ -1,7 +1,3 @@
|
|||
const { CoverageSubprovider, Web3ProviderEngine } = require('@0x/sol-coverage')
|
||||
const { TruffleArtifactAdapter } = require('@0x/sol-trace')
|
||||
const RPCSubprovider = require('web3-provider-engine/subproviders/rpc')
|
||||
|
||||
const contractsBuildDirectory = './build/contracts'
|
||||
const evmVersion = 'byzantium'
|
||||
const mochaOptions =
|
||||
|
@ -15,32 +11,10 @@ const mochaOptions =
|
|||
}
|
||||
: {}
|
||||
|
||||
const projectRoot = ''
|
||||
const solcVersion = '0.4.24+commit.e67f0147'
|
||||
const defaultFromAddress = '0x5409ed021d9299bf6814279a6a1411a7e866a631'
|
||||
const isVerbose = true
|
||||
const artifactAdapter = new TruffleArtifactAdapter(projectRoot, solcVersion)
|
||||
const provider = new Web3ProviderEngine()
|
||||
if (process.env.SOLIDITY_COVERAGE === 'true') {
|
||||
global.coverageSubprovider = new CoverageSubprovider(artifactAdapter, defaultFromAddress, {
|
||||
isVerbose,
|
||||
ignoreFilesGlobs: ['**/Migrations.sol', '**/node_modules/**', '**/mocks/**', '**/interfaces/**', '**/helpers/**']
|
||||
})
|
||||
provider.addProvider(global.coverageSubprovider)
|
||||
provider.addProvider(new RPCSubprovider({ rpcUrl: 'http://localhost:8545' }))
|
||||
provider.start(err => {
|
||||
if (err !== undefined) {
|
||||
process.exit(1)
|
||||
}
|
||||
})
|
||||
provider.send = provider.sendAsync.bind(provider)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
contracts_build_directory: contractsBuildDirectory,
|
||||
networks: {
|
||||
development: {
|
||||
provider,
|
||||
network_id: '*',
|
||||
gas: 10000000,
|
||||
disableConfirmationListener: true
|
||||
|
@ -48,7 +22,7 @@ module.exports = {
|
|||
ganache: {
|
||||
host: '127.0.0.1',
|
||||
port: 8545,
|
||||
network_id: '*', // eslint-disable-line camelcase
|
||||
network_id: '1337', // eslint-disable-line camelcase
|
||||
gasPrice: 100000000000,
|
||||
gas: 10000000,
|
||||
disableConfirmationListener: true
|
||||
|
@ -66,5 +40,6 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
},
|
||||
mocha: mochaOptions
|
||||
mocha: mochaOptions,
|
||||
plugins: ['solidity-coverage']
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue