Skip to content

Commit

Permalink
Merge pull request #289 from poanetwork/rsk-testnet-support
Browse files Browse the repository at this point in the history
RSK testnet support
  • Loading branch information
vbaranov authored Jun 11, 2019
2 parents eff5942 + 70157a7 commit 3b81f28
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 56 deletions.
8 changes: 8 additions & 0 deletions app/scripts/controllers/network/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const KOVAN = 'kovan'
const GOERLI_TESTNET = 'goerli_testnet'
const CLASSIC = 'classic'
const RSK = 'rsk'
const RSK_TESTNET = 'rsk_testnet'
const LOCALHOST = 'localhost'

const POA_CODE = 99
Expand All @@ -20,6 +21,7 @@ const KOVAN_CODE = 42
const GOERLI_TESTNET_CODE = 5
const CLASSIC_CODE = 61
const RSK_CODE = 30
const RSK_TESTNET_CODE = 31

const POA_DISPLAY_NAME = 'POA Core'
const DAI_DISPLAY_NAME = 'xDai Chain'
Expand All @@ -31,6 +33,7 @@ const KOVAN_DISPLAY_NAME = 'Kovan'
const GOERLI_TESTNET_DISPLAY_NAME = 'Görli Testnet'
const CLASSIC_DISPLAY_NAME = 'Ethereum Classic'
const RSK_DISPLAY_NAME = 'RSK Mainnet'
const RSK_TESTNET_DISPLAY_NAME = 'RSK Testnet'

const DROPDOWN_POA_DISPLAY_NAME = POA_DISPLAY_NAME
const DROPDOWN_DAI_DISPLAY_NAME = DAI_DISPLAY_NAME
Expand All @@ -42,6 +45,7 @@ const DROPDOWN_KOVAN_DISPLAY_NAME = 'Kovan Test Net'
const DROPDOWN_GOERLI_TESTNET_DISPLAY_NAME = 'Görli Test Net'
const DROPDOWN_CLASSIC_DISPLAY_NAME = 'Ethereum Classic'
const DROPDOWN_RSK_DISPLAY_NAME = 'RSK Main Net'
const DROPDOWN_RSK_TESTNET_DISPLAY_NAME = 'RSK Test Net'

const chainTypes = {
TEST: 1,
Expand All @@ -59,6 +63,7 @@ module.exports = {
GOERLI_TESTNET,
CLASSIC,
RSK,
RSK_TESTNET,
LOCALHOST,
POA_CODE,
DAI_CODE,
Expand All @@ -70,6 +75,7 @@ module.exports = {
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
RSK_TESTNET_CODE,
POA_DISPLAY_NAME,
DAI_DISPLAY_NAME,
POA_SOKOL_DISPLAY_NAME,
Expand All @@ -80,6 +86,7 @@ module.exports = {
GOERLI_TESTNET_DISPLAY_NAME,
CLASSIC_DISPLAY_NAME,
RSK_DISPLAY_NAME,
RSK_TESTNET_DISPLAY_NAME,
DROPDOWN_POA_DISPLAY_NAME,
DROPDOWN_DAI_DISPLAY_NAME,
DROPDOWN_POA_SOKOL_DISPLAY_NAME,
Expand All @@ -90,5 +97,6 @@ module.exports = {
DROPDOWN_GOERLI_TESTNET_DISPLAY_NAME,
DROPDOWN_CLASSIC_DISPLAY_NAME,
DROPDOWN_RSK_DISPLAY_NAME,
DROPDOWN_RSK_TESTNET_DISPLAY_NAME,
chainTypes,
}
7 changes: 6 additions & 1 deletion app/scripts/controllers/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ const {
GOERLI_TESTNET,
CLASSIC,
RSK,
RSK_TESTNET,
POA_CODE,
DAI_CODE,
POA_SOKOL_CODE,
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
RSK_TESTNET_CODE,
} = require('./enums')
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET]

Expand Down Expand Up @@ -130,7 +132,8 @@ module.exports = class NetworkController extends EventEmitter {
type === DAI ||
type === GOERLI_TESTNET ||
type === CLASSIC ||
type === RSK
type === RSK ||
type === RSK_TESTNET
, `NetworkController - Unknown rpc type "${type}"`)
const providerConfig = { type }
this.providerConfig = providerConfig
Expand Down Expand Up @@ -178,6 +181,8 @@ module.exports = class NetworkController extends EventEmitter {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(CLASSIC_CODE)[0] })
} else if (type === RSK) {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(RSK_CODE)[0] })
} else if (type === RSK_TESTNET) {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(RSK_TESTNET_CODE)[0] })
} else if (type === LOCALHOST) {
this._configureLocalhostProvider()
// url-based rpc endpoints
Expand Down
90 changes: 52 additions & 38 deletions app/scripts/controllers/network/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
GOERLI_TESTNET,
CLASSIC,
RSK,
RSK_TESTNET,
POA_CODE,
DAI_CODE,
POA_SOKOL_CODE,
Expand All @@ -19,6 +20,7 @@ const {
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
RSK_TESTNET_CODE,
POA_DISPLAY_NAME,
DAI_DISPLAY_NAME,
POA_SOKOL_DISPLAY_NAME,
Expand All @@ -29,6 +31,7 @@ const {
GOERLI_TESTNET_DISPLAY_NAME,
CLASSIC_DISPLAY_NAME,
RSK_DISPLAY_NAME,
RSK_TESTNET_DISPLAY_NAME,
DROPDOWN_POA_DISPLAY_NAME,
DROPDOWN_DAI_DISPLAY_NAME,
DROPDOWN_POA_SOKOL_DISPLAY_NAME,
Expand All @@ -39,6 +42,7 @@ const {
DROPDOWN_GOERLI_TESTNET_DISPLAY_NAME,
DROPDOWN_CLASSIC_DISPLAY_NAME,
DROPDOWN_RSK_DISPLAY_NAME,
DROPDOWN_RSK_TESTNET_DISPLAY_NAME,
chainTypes,
} = require('./enums')

Expand Down Expand Up @@ -67,19 +71,8 @@ const DAI_OBJ = {
networks[DAI_CODE] = DAI_OBJ
networks[DAI] = DAI_OBJ

const POA_SOKOL_OBJ = {
order: 3,
chainType: TEST,
providerName: POA_SOKOL,
networkID: POA_SOKOL_CODE,
displayName: POA_SOKOL_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_POA_SOKOL_DISPLAY_NAME,
}
networks[POA_SOKOL_CODE] = POA_SOKOL_OBJ
networks[POA_SOKOL] = POA_SOKOL_OBJ

const MAINNET_OBJ = {
order: 4,
order: 3,
chainType: PROD,
providerName: MAINNET,
networkID: MAINNET_CODE,
Expand All @@ -90,7 +83,7 @@ networks[MAINNET_CODE] = MAINNET_OBJ
networks[MAINNET] = MAINNET_OBJ

const CLASSIC_OBJ = {
order: 5,
order: 4,
chainType: PROD,
providerName: CLASSIC,
networkID: CLASSIC_CODE,
Expand All @@ -100,16 +93,25 @@ const CLASSIC_OBJ = {
networks[CLASSIC_CODE] = CLASSIC_OBJ
networks[CLASSIC] = CLASSIC_OBJ

const ROPSTEN_OBJ = {
const RSK_OBJ = {
order: 5,
providerName: RSK,
networkID: RSK_CODE,
displayName: RSK_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_RSK_DISPLAY_NAME,
}
networks[RSK_CODE] = RSK_OBJ
networks[RSK] = RSK_OBJ

const GOERLI_TESTNET_OBJ = {
order: 6,
chainType: TEST,
providerName: ROPSTEN,
networkID: ROPSTEN_CODE,
displayName: ROPSTEN_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_ROPSTEN_DISPLAY_NAME,
providerName: GOERLI_TESTNET,
networkID: GOERLI_TESTNET_CODE,
displayName: GOERLI_TESTNET_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_GOERLI_TESTNET_DISPLAY_NAME,
}
networks[ROPSTEN_CODE] = ROPSTEN_OBJ
networks[ROPSTEN] = ROPSTEN_OBJ
networks[GOERLI_TESTNET_CODE] = GOERLI_TESTNET_OBJ
networks[GOERLI_TESTNET] = GOERLI_TESTNET_OBJ

const KOVAN_OBJ = {
order: 7,
Expand All @@ -122,9 +124,20 @@ const KOVAN_OBJ = {
networks[KOVAN_CODE] = KOVAN_OBJ
networks[KOVAN] = KOVAN_OBJ

const RINKEBY_OBJ = {
const POA_SOKOL_OBJ = {
order: 8,
chainType: TEST,
providerName: POA_SOKOL,
networkID: POA_SOKOL_CODE,
displayName: POA_SOKOL_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_POA_SOKOL_DISPLAY_NAME,
}
networks[POA_SOKOL_CODE] = POA_SOKOL_OBJ
networks[POA_SOKOL] = POA_SOKOL_OBJ

const RINKEBY_OBJ = {
order: 9,
chainType: TEST,
providerName: RINKEBY,
networkID: RINKEBY_CODE,
displayName: RINKEBY_DISPLAY_NAME,
Expand All @@ -133,25 +146,26 @@ const RINKEBY_OBJ = {
networks[RINKEBY_CODE] = RINKEBY_OBJ
networks[RINKEBY] = RINKEBY_OBJ

const GOERLI_TESTNET_OBJ = {
order: 9,
providerName: GOERLI_TESTNET,
networkID: GOERLI_TESTNET_CODE,
displayName: GOERLI_TESTNET_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_GOERLI_TESTNET_DISPLAY_NAME,
const ROPSTEN_OBJ = {
order: 10,
chainType: TEST,
providerName: ROPSTEN,
networkID: ROPSTEN_CODE,
displayName: ROPSTEN_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_ROPSTEN_DISPLAY_NAME,
}
networks[GOERLI_TESTNET_CODE] = GOERLI_TESTNET_OBJ
networks[GOERLI_TESTNET] = GOERLI_TESTNET_OBJ
networks[ROPSTEN_CODE] = ROPSTEN_OBJ
networks[ROPSTEN] = ROPSTEN_OBJ

const RSK_OBJ = {
order: 10,
providerName: RSK,
networkID: RSK_CODE,
displayName: RSK_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_RSK_DISPLAY_NAME,
const RSK_TESTNET_OBJ = {
order: 11,
providerName: RSK_TESTNET,
networkID: RSK_TESTNET_CODE,
displayName: RSK_TESTNET_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_RSK_TESTNET_DISPLAY_NAME,
}
networks[RSK_CODE] = RSK_OBJ
networks[RSK] = RSK_OBJ
networks[RSK_TESTNET_CODE] = RSK_TESTNET_OBJ
networks[RSK_TESTNET] = RSK_TESTNET_OBJ

const getNetworkDisplayName = key => networks[key].displayName

Expand Down
4 changes: 3 additions & 1 deletion app/scripts/lib/buy-eth-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const {
RINKEBY_CODE,
KOVAN_CODE,
GOERLI_TESTNET_CODE,
RSK_CODE} = require('../controllers/network/enums')
RSK_CODE,
RSK_TESTNET_CODE} = require('../controllers/network/enums')

/**
* Gives the caller a url at which the user can acquire coin, depending on the network they are in
Expand Down Expand Up @@ -43,6 +44,7 @@ function getBuyEthUrl ({ network, amount, address, ind }) {
case RINKEBY_CODE:
case KOVAN_CODE:
case POA_SOKOL_CODE:
case RSK_TESTNET_CODE:
case GOERLI_TESTNET_CODE:
url = getFaucets(network)[ind]
break
Expand Down
4 changes: 2 additions & 2 deletions old-ui/app/components/fiat-value.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { Component } from 'react'
import { formatBalance, countSignificantDecimals } from '../util'
import PropTypes from 'prop-types'
import { DAI_CODE, POA_SOKOL_CODE, GOERLI_TESTNET_CODE } from '../../../app/scripts/controllers/network/enums'
import { DAI_CODE, POA_SOKOL_CODE, RSK_TESTNET_CODE, GOERLI_TESTNET_CODE } from '../../../app/scripts/controllers/network/enums'

class FiatValue extends Component {
render = () => {
const props = this.props
let { conversionRate } = props
const { currentCurrency, network } = props
const isTestnet = parseInt(network) === POA_SOKOL_CODE || parseInt(network) === GOERLI_TESTNET_CODE
const isTestnet = parseInt(network) === POA_SOKOL_CODE || parseInt(network) === RSK_TESTNET_CODE || parseInt(network) === GOERLI_TESTNET_CODE
const isDai = parseInt(network) === DAI_CODE
if (isTestnet) {
conversionRate = 0
Expand Down
4 changes: 3 additions & 1 deletion old-ui/app/components/transaction-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const { POA_CODE,
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
RSK_TESTNET_CODE,
} = require('../../../app/scripts/controllers/network/enums')

const mapDispatchToProps = dispatch => {
Expand Down Expand Up @@ -86,7 +87,8 @@ TransactionListItem.prototype.render = function () {
numericNet === DAI_CODE ||
numericNet === GOERLI_TESTNET_CODE ||
numericNet === CLASSIC_CODE ||
numericNet === RSK_CODE
numericNet === RSK_CODE ||
numericNet === RSK_TESTNET_CODE

var isMsg = ('msgParams' in transaction)
var isTx = ('txParams' in transaction)
Expand Down
4 changes: 2 additions & 2 deletions old-ui/app/conf-tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import PendingMsg from './components/pending-msg'
import PendingPersonalMsg from './components/pending-personal-msg'
import PendingTypedMsg from './components/pending-typed-msg'
const Loading = require('./components/loading')
const { DAI_CODE, POA_SOKOL_CODE, GOERLI_TESTNET_CODE } = require('../../app/scripts/controllers/network/enums')
const { DAI_CODE, POA_SOKOL_CODE, RSK_TESTNET_CODE, GOERLI_TESTNET_CODE } = require('../../app/scripts/controllers/network/enums')
const { getMetaMaskAccounts } = require('../../ui/app/selectors')

module.exports = connect(mapStateToProps)(ConfirmTxScreen)
Expand Down Expand Up @@ -57,7 +57,7 @@ ConfirmTxScreen.prototype.render = function () {
unapprovedMsgs, unapprovedPersonalMsgs, unapprovedTypedMessages, blockGasLimit } = props
let { conversionRate } = props

const isTestnet = parseInt(network) === POA_SOKOL_CODE || parseInt(network) === GOERLI_TESTNET_CODE
const isTestnet = parseInt(network) === POA_SOKOL_CODE || parseInt(network) === RSK_TESTNET_CODE || parseInt(network) === GOERLI_TESTNET_CODE
const isDai = parseInt(network) === DAI_CODE
if (isTestnet) {
conversionRate = 0
Expand Down
1 change: 1 addition & 0 deletions test/e2e/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ module.exports = {
RINKEBY: 'rinkeby',
GOERLI: 'goerli',
RSK: 'rsk',
RSK_TESTNET: 'rsk_testnet',
LOCALHOST: 'localhost',
CUSTOM: 'http://test.com',
},
Expand Down
23 changes: 13 additions & 10 deletions test/e2e/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,38 +117,41 @@ class Functions {
case NETWORKS.DAI:
counter = 1
break
case NETWORKS.SOKOL:
case NETWORKS.MAINNET:
counter = 2
break
case NETWORKS.MAINNET:
case NETWORKS.CLASSIC:
counter = 3
break
case NETWORKS.CLASSIC:
case NETWORKS.RSK:
counter = 4
break
case NETWORKS.ROPSTEN:
case NETWORKS.GOERLI:
counter = 5
break
case NETWORKS.KOVAN:
counter = 6
break
case NETWORKS.RINKEBY:
case NETWORKS.SOKOL:
counter = 7
break
case NETWORKS.GOERLI:
case NETWORKS.RINKEBY:
counter = 8
break
case NETWORKS.RSK:
case NETWORKS.ROPSTEN:
counter = 9
break
case NETWORKS.LOCALHOST:
case NETWORKS.RSK_TESTNET:
counter = 10
break
case NETWORKS.CUSTOM:
case NETWORKS.LOCALHOST:
counter = 11
break
case NETWORKS.CUSTOM:
counter = 12
break
default:
counter = 10
counter = 11
}
await this.driver.executeScript("document.getElementsByClassName('dropdown-menu-item')[" + counter + '].click();')
}
Expand Down
Loading

0 comments on commit 3b81f28

Please sign in to comment.