From dc27f68e002ed76e5a3f6bc1a672affd5860d596 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 May 2019 11:30:24 -0300 Subject: [PATCH 1/5] Update contract submodule --- submodules/poa-bridge-contracts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/poa-bridge-contracts b/submodules/poa-bridge-contracts index c7c84cf1..492f6d01 160000 --- a/submodules/poa-bridge-contracts +++ b/submodules/poa-bridge-contracts @@ -1 +1 @@ -Subproject commit c7c84cf1d29787eee770c28d700f9c3fb5a61c73 +Subproject commit 492f6d010a1324676801df918f0449965e770c64 From 46e3846f83ed2867ca77f8d102fb2e005f60f79a Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 May 2019 11:31:34 -0300 Subject: [PATCH 2/5] Get token ERC type on foreign network --- src/components/Bridge.js | 10 +++++----- src/stores/ForeignStore.js | 5 ++++- src/stores/utils/bridgeMode.js | 5 +++++ src/stores/utils/contract.js | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/components/Bridge.js b/src/components/Bridge.js index 5e28eb52..944795ad 100644 --- a/src/components/Bridge.js +++ b/src/components/Bridge.js @@ -4,7 +4,7 @@ import { toHex } from 'web3-utils' import foreignLogoPurple from '../assets/images/logos/logo-poa-20-purple@2x.png' import homeLogoPurple from '../assets/images/logos/logo-poa-sokol-purple@2x.png' import swal from 'sweetalert' -import { BRIDGE_MODES } from '../stores/utils/bridgeMode' +import { BRIDGE_MODES, ERC_TYPES } from '../stores/utils/bridgeMode' import { BridgeAddress } from './index' import { BridgeForm } from './index' import { BridgeNetwork } from './index' @@ -111,8 +111,8 @@ export class Bridge extends React.Component { } async _sendToForeign(amount){ - const { web3Store, foreignStore, alertStore, txStore, bridgeMode } = this.props.RootStore - const isExternalErc20 = bridgeMode === BRIDGE_MODES.ERC_TO_ERC || bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE + const { web3Store, foreignStore, alertStore, txStore } = this.props.RootStore + const isExternalErc20 = foreignStore.tokenType === ERC_TYPES.ERC20 const { isLessThan, isGreaterThan } = this if(web3Store.metamaskNet.id.toString() !== web3Store.foreignNet.id.toString()){ swal("Error", `Please switch wallet to ${web3Store.foreignNet.name} network`, "error") @@ -257,8 +257,8 @@ export class Bridge extends React.Component { } loadForeignDetails = () => { - const { web3Store, foreignStore, bridgeMode } = this.props.RootStore - const isExternalErc20 = bridgeMode === BRIDGE_MODES.ERC_TO_ERC || bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE + const { web3Store, foreignStore } = this.props.RootStore + const isExternalErc20 = foreignStore.tokenType === ERC_TYPES.ERC20 const foreignURL = new URL(web3Store.FOREIGN_HTTP_PARITY_URL) const foreignDisplayUrl = `${foreignURL.protocol}//${foreignURL.hostname}` diff --git a/src/stores/ForeignStore.js b/src/stores/ForeignStore.js index 63cf0702..52b5da51 100644 --- a/src/stores/ForeignStore.js +++ b/src/stores/ForeignStore.js @@ -18,7 +18,8 @@ import { getFeeManagerMode, ZERO_ADDRESS, getDeployedAtBlock, - getValidatorList + getValidatorList, + getTokenType } from './utils/contract' import { balanceLoaded, removePendingTransaction } from './utils/testUtils' import sleep from './utils/sleep' @@ -50,6 +51,7 @@ class ForeignStore { @observable totalSpentPerDay = 0 @observable tokenAddress = ''; @observable feeEventsFinished = false + @observable tokenType = '' feeManager = { totalFeeDistributedFromSignatures: BN(0), totalFeeDistributedFromAffirmation: BN(0) @@ -132,6 +134,7 @@ class ForeignStore { ? await getErc20TokenAddress(this.foreignBridge) : await getErc677TokenAddress(this.foreignBridge) this.tokenContract = new this.foreignWeb3.eth.Contract(ERC677_ABI, this.tokenAddress); + this.tokenType = await getTokenType(this.tokenContract, this.FOREIGN_BRIDGE_ADDRESS) const alternativeContract = new this.foreignWeb3.eth.Contract(ERC20Bytes32Abi, this.tokenAddress); try { this.symbol =await getSymbol(this.tokenContract) diff --git a/src/stores/utils/bridgeMode.js b/src/stores/utils/bridgeMode.js index ac24bfba..56b6082f 100644 --- a/src/stores/utils/bridgeMode.js +++ b/src/stores/utils/bridgeMode.js @@ -17,6 +17,11 @@ export const FEE_MANAGER_MODE = { UNDEFINED: 'UNDEFINED' } +export const ERC_TYPES = { + ERC677: 'ERC677', + ERC20: 'ERC20' +} + export const getBridgeABIs = (bridgeMode) => { let HOME_ABI = null let FOREIGN_ABI = null diff --git a/src/stores/utils/contract.js b/src/stores/utils/contract.js index 67d317a1..57ccc28f 100644 --- a/src/stores/utils/contract.js +++ b/src/stores/utils/contract.js @@ -2,6 +2,7 @@ import BN from 'bignumber.js' import { fromDecimals } from './decimals' import { fromWei } from 'web3-utils' import { abi as rewardableValidatorsAbi } from '../../contracts/RewardableValidators' +import { ERC_TYPES } from "./bridgeMode" export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' @@ -149,3 +150,16 @@ export const getDeployedAtBlock = async (contract) => { return 0 } } + +export const getTokenType = async (contract, bridgeAddress) => { + try { + const bridgeContract = await contract.methods.bridgeContract().call() + if (bridgeContract === bridgeAddress) { + return ERC_TYPES.ERC677 + } else { + return ERC_TYPES.ERC20 + } + } catch (e) { + return ERC_TYPES.ERC20 + } +} From b7cce164549f03128b52965da05ccda631cf58da Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 May 2019 11:31:47 -0300 Subject: [PATCH 3/5] Add getTokenType unit test --- src/stores/utils/__tests__/contract.test.js | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/stores/utils/__tests__/contract.test.js diff --git a/src/stores/utils/__tests__/contract.test.js b/src/stores/utils/__tests__/contract.test.js new file mode 100644 index 00000000..5c096f8e --- /dev/null +++ b/src/stores/utils/__tests__/contract.test.js @@ -0,0 +1,63 @@ +import { getTokenType } from '../contract' +import { ERC_TYPES } from '../bridgeMode' + +describe('getTokenType', () => { + it('should return ERC677 if bridgeContract is equal to bridgeAddress', async () => { + // Given + const bridgeAddress = '0xCecBE80Ed3548dE11D7d2D922a36576eA40C4c26' + const contract = { + methods: { + bridgeContract: () => { + return { + call: () => Promise.resolve(bridgeAddress) + } + } + } + } + + // When + const type = await getTokenType(contract, bridgeAddress) + + // Then + expect(type).toEqual(ERC_TYPES.ERC677) + }) + it('should return ERC20 if bridgeContract is not equal to bridgeAddress', async () => { + // Given + const bridgeAddress = '0xCecBE80Ed3548dE11D7d2D922a36576eA40C4c26' + const contract = { + methods: { + bridgeContract: () => { + return { + call: () => Promise.resolve('0xBFCb120F7B1de491262CA4D9D8Eba70438b6896E') + } + } + } + } + + // When + const type = await getTokenType(contract, bridgeAddress) + + // Then + expect(type).toEqual(ERC_TYPES.ERC20) + }) + it('should return ERC20 if bridgeContract is not present', async () => { + // Given + const bridgeAddress = '0xCecBE80Ed3548dE11D7d2D922a36576eA40C4c26' + const contract = { + methods: { + bridgeContract: () => { + return { + call: () => Promise.reject() + } + } + } + } + + // When + const type = await getTokenType(contract, bridgeAddress) + + // Then + expect(type).toEqual(ERC_TYPES.ERC20) + }) +}) + From 22ec13d78b412288730097fac03fb611ede38f1c Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 May 2019 13:28:02 -0300 Subject: [PATCH 4/5] Add NetworkDetails unit tests --- src/components/NetworkDetails.js | 2 +- .../__tests__/NetworkDetails.test.js | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/components/__tests__/NetworkDetails.test.js diff --git a/src/components/NetworkDetails.js b/src/components/NetworkDetails.js index 062611b6..5f5263d2 100644 --- a/src/components/NetworkDetails.js +++ b/src/components/NetworkDetails.js @@ -34,7 +34,7 @@ export const NetworkDetails = ({ : numeral(balance).format('0,0.000', Math.floor) return ( -
+
diff --git a/src/components/__tests__/NetworkDetails.test.js b/src/components/__tests__/NetworkDetails.test.js new file mode 100644 index 00000000..486b5270 --- /dev/null +++ b/src/components/__tests__/NetworkDetails.test.js @@ -0,0 +1,57 @@ +import React from 'react' +import { render, cleanup } from 'react-testing-library' +import { NetworkDetails } from '../NetworkDetails' +import 'jest-dom/extend-expect' + +afterEach(cleanup) + +const baseData = { + address: "0xCecBE80Ed3548dE11D7d2D922a36576eA40C4c26", + balance: "99.99", + currency: "TEST", + displayTokenAddress: true, + getExplorerAddressUrl: () => {}, + isHome: false, + maxCurrentLimit: "20000", + maxPerTx: "2000", + minPerTx: "0.01", + tokenAddress: "0xb69d9C58C258080eABF499270c778bBDE38dd6Ac", + tokenName: "TEST", + totalSupply: "100", + url: "https://ropsten.infura.io" +} + +describe('NetworkDetails', () => { + it('should display bridge limits information ', () => { + // Given + const data = { + ...baseData, + displayBridgeLimits: true + } + + // When + const { queryByTestId } = render() + + // Then + const container = queryByTestId('network-details') + expect(container).toHaveTextContent('Minimum Amount Per Transaction') + expect(container).toHaveTextContent('Maximum Amount Per Transaction') + expect(container).toHaveTextContent('Remaining Daily') + }) + it('should not display bridge limits information ', () => { + // Given + const data = { + ...baseData, + displayBridgeLimits: false + } + + // When + const { queryByTestId } = render() + + // Then + const container = queryByTestId('network-details') + expect(container).not.toHaveTextContent('Minimum Amount Per Transaction') + expect(container).not.toHaveTextContent('Maximum Amount Per Transaction') + expect(container).not.toHaveTextContent('Remaining Daily') + }) +}) From e6f106f763d6b5dd753526dd11f4236a642365d2 Mon Sep 17 00:00:00 2001 From: Gerardo Nardelli Date: Mon, 6 May 2019 13:40:50 -0300 Subject: [PATCH 5/5] Update parity version on e2e tests --- e2e-script/parity/Dockerfile | 2 +- e2e-script/parity/Dockerfile-foreign | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e-script/parity/Dockerfile b/e2e-script/parity/Dockerfile index 2570fbec..36f56127 100644 --- a/e2e-script/parity/Dockerfile +++ b/e2e-script/parity/Dockerfile @@ -1,4 +1,4 @@ -FROM parity/parity:v2.2.11 +FROM parity/parity:v2.3.3 WORKDIR /stuff diff --git a/e2e-script/parity/Dockerfile-foreign b/e2e-script/parity/Dockerfile-foreign index 3b04a3a4..4cb90c07 100644 --- a/e2e-script/parity/Dockerfile-foreign +++ b/e2e-script/parity/Dockerfile-foreign @@ -1,4 +1,4 @@ -FROM parity/parity:v2.2.11 +FROM parity/parity:v2.3.3 WORKDIR /stuff