Support of RSK Mainnet

This commit is contained in:
Victor Baranov 2019-06-06 13:12:46 +03:00
parent cd7ed1bd9a
commit 248451035b
11 changed files with 164 additions and 7 deletions

View File

@ -25,11 +25,13 @@ const {
DAI,
GOERLI_TESTNET,
CLASSIC,
RSK,
POA_CODE,
DAI_CODE,
POA_SOKOL_CODE,
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
} = require('./enums')
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET]
@ -127,7 +129,8 @@ module.exports = class NetworkController extends EventEmitter {
type === POA ||
type === DAI ||
type === GOERLI_TESTNET ||
type === CLASSIC
type === CLASSIC ||
type === RSK
, `NetworkController - Unknown rpc type "${type}"`)
const providerConfig = { type }
this.providerConfig = providerConfig
@ -173,6 +176,8 @@ module.exports = class NetworkController extends EventEmitter {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(GOERLI_TESTNET_CODE)[0] })
} else if (type === CLASSIC) {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(CLASSIC_CODE)[0] })
} else if (type === RSK) {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(RSK_CODE)[0] })
} else if (type === LOCALHOST) {
this._configureLocalhostProvider()
// url-based rpc endpoints

View File

@ -8,6 +8,7 @@ const {
KOVAN,
GOERLI_TESTNET,
CLASSIC,
RSK,
POA_CODE,
DAI_CODE,
POA_SOKOL_CODE,
@ -17,6 +18,7 @@ const {
KOVAN_CODE,
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
POA_DISPLAY_NAME,
DAI_DISPLAY_NAME,
POA_SOKOL_DISPLAY_NAME,
@ -26,6 +28,7 @@ const {
KOVAN_DISPLAY_NAME,
GOERLI_TESTNET_DISPLAY_NAME,
CLASSIC_DISPLAY_NAME,
RSK_DISPLAY_NAME,
DROPDOWN_POA_DISPLAY_NAME,
DROPDOWN_DAI_DISPLAY_NAME,
DROPDOWN_POA_SOKOL_DISPLAY_NAME,
@ -35,6 +38,7 @@ const {
DROPDOWN_KOVAN_DISPLAY_NAME,
DROPDOWN_GOERLI_TESTNET_DISPLAY_NAME,
DROPDOWN_CLASSIC_DISPLAY_NAME,
DROPDOWN_RSK_DISPLAY_NAME,
chainTypes,
} = require('./enums')
@ -139,6 +143,16 @@ const GOERLI_TESTNET_OBJ = {
networks[GOERLI_TESTNET_CODE] = GOERLI_TESTNET_OBJ
networks[GOERLI_TESTNET] = GOERLI_TESTNET_OBJ
const RSK_OBJ = {
order: 10,
providerName: RSK,
networkID: RSK_CODE,
displayName: RSK_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_RSK_DISPLAY_NAME,
}
networks[RSK_CODE] = RSK_OBJ
networks[RSK] = RSK_OBJ
const getNetworkDisplayName = key => networks[key].displayName
module.exports = {

View File

@ -14,7 +14,8 @@ const {
ROPSTEN_CODE,
RINKEBY_CODE,
KOVAN_CODE,
GOERLI_TESTNET_CODE} = require('../controllers/network/enums')
GOERLI_TESTNET_CODE,
RSK_CODE} = require('../controllers/network/enums')
/**
* Gives the caller a url at which the user can acquire coin, depending on the network they are in
@ -35,6 +36,7 @@ function getBuyEthUrl ({ network, amount, address, ind }) {
case POA_CODE:
case DAI_CODE:
case CLASSIC_CODE:
case RSK_CODE:
url = getExchanges({network, amount, address})[ind].link
break
case ROPSTEN_CODE:
@ -109,6 +111,21 @@ function getExchanges ({network, amount, address}) {
link: 'https://dai-bridge.poa.network/',
},
]
case RSK_CODE:
return [
{
name: 'Huobi',
link: 'https://www.huobi.com/',
},
{
name: 'Bitfinex',
link: 'https://www.bitfinex.com/',
},
{
name: 'Bitso',
link: 'https://bitso.com/',
},
]
default:
return []
}

View File

@ -24,6 +24,7 @@ const { POA_CODE,
KOVAN_CODE,
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
} = require('../../../app/scripts/controllers/network/enums')
const mapDispatchToProps = dispatch => {
@ -84,7 +85,8 @@ TransactionListItem.prototype.render = function () {
numericNet === POA_CODE ||
numericNet === DAI_CODE ||
numericNet === GOERLI_TESTNET_CODE ||
numericNet === CLASSIC_CODE
numericNet === CLASSIC_CODE ||
numericNet === RSK_CODE
var isMsg = ('msgParams' in transaction)
var isTx = ('txParams' in transaction)

View File

@ -295,6 +295,8 @@ module.exports = {
buttons: {
send: By.css('#app-content > div > div.app-primary.from-right > div > div > div.flex-row > button:nth-child(4)'),
buy: By.css('#app-content > div > div.app-primary.from-right > div > div > div.flex-row > button:nth-child(3)'),
sendRSK: By.css('#app-content > div > div.app-primary.from-left > div > div > div.flex-row > button:nth-child(4)'),
buyRSK: By.css('#app-content > div > div.app-primary.from-left > div > div > div.flex-row > button:nth-child(3)'),
sendText: 'Send',
save: By.className('editable-button'),
},
@ -323,6 +325,7 @@ module.exports = {
},
buyEther: {
title: By.className('flex-center buy-title'),
faucetLinkRSK: By.className('buy-option cursor-pointer'),
buttonArrow: By.className('fa fa-arrow-left fa-lg cursor-pointer'),
},
info: {
@ -400,6 +403,7 @@ module.exports = {
KOVAN: 'kovan',
RINKEBY: 'rinkeby',
GOERLI: 'goerli',
RSK: 'rsk',
LOCALHOST: 'localhost',
CUSTOM: 'http://test.com',
},

View File

@ -138,14 +138,17 @@ class Functions {
case NETWORKS.GOERLI:
counter = 8
break
case NETWORKS.LOCALHOST:
case NETWORKS.RSK:
counter = 9
break
case NETWORKS.CUSTOM:
case NETWORKS.LOCALHOST:
counter = 10
break
case NETWORKS.CUSTOM:
counter = 11
break
default:
counter = 9
counter = 10
}
await this.driver.executeScript("document.getElementsByClassName('dropdown-menu-item')[" + counter + '].click();')
}

View File

@ -13,6 +13,7 @@ const deleteImportedAccount = require(`${testsFolder}/delete-imported-account.sp
const signData = require(`${testsFolder}/sign-data.spec`)
const exportPrivateKey = require(`${testsFolder}/export-private-key.spec`)
const importGanacheSeedPhrase = require(`${testsFolder}/import-ganache-seed-phrase.spec`)
const RSKNetworkTests = require(`${testsFolder}/RSK-network-tests.js`)
const checkEmittedEvents = require(`${testsFolder}/check-emitted-events.spec`)
const addCustomToken = require(`${testsFolder}/add-token-custom.spec`)
const changePassword = require(`${testsFolder}/change-password.spec`)
@ -115,6 +116,10 @@ describe('Metamask popup page', async function () {
await importGanacheSeedPhrase(f, account2, password)
})
describe('RSK network tests', async () => {
await RSKNetworkTests(f, account1)
})
describe('Check the filter of emitted events', async () => {
await checkEmittedEvents(f, account1, account2)
})

View File

@ -0,0 +1,90 @@
const assert = require('assert')
const { screens, elements, NETWORKS } = require('../elements')
const RSKNetworkTests = async (f, account1) => {
it('connects to RSK mainnet', async function () {
await f.setProvider(NETWORKS.RSK)
await f.delay(2000)
})
it('connects to RSK testnet', async function () {
await f.setProvider(NETWORKS.RSK_TESTNET)
await f.delay(2000)
})
it('checks zero exchange rate for RSK testnet', async function () {
const balanceField = await f.waitUntilShowUp(screens.main.balance)
const balanceUSDField = await f.waitUntilShowUp(screens.main.balanceUSD)
await f.delay(2000)
const balance = await balanceField.getText()
const balanceUSD = await balanceUSDField.getText()
console.log('Balance = ' + parseFloat(balance))
console.log('balanceUSD = ' + parseFloat(balanceUSD))
assert.equal(parseFloat(balance) > 0.0001, true, 'Balance of account ' + account1 + ' is TOO LOW in RSK testnet !!! Please refill it!!!!')
assert.equal(parseFloat(balanceUSD), 0, 'USD balance of account is not zero')
})
it('opens RSK faucet', async function () {
await f.waitUntilShowUp(screens.main.buttons.buyRSK)
const buttons = await f.driver.findElements(screens.main.buttons.buyRSK)
assert.equal(buttons.length, 1, 'main screen isn\'t displayed')
const buyButton = buttons[0]
const buyButtonText = await buyButton.getText()
assert.equal(buyButtonText, 'Buy', 'button has incorrect name')
await buyButton.click()
await f.delay(2000)
const title = await f.waitUntilShowUp(screens.buyEther.title)
assert.equal(await title.getText(), 'Buy RBTC', "screen 'Buy RBTC' has incorrect title text")
await f.waitUntilShowUp(screens.buyEther.faucetLinkRSK)
const faucetButtons = await f.driver.findElements(screens.buyEther.faucetLinkRSK)
assert.equal(faucetButtons.length, 1, 'there is no faucet button on the screen')
const faucetLinkButton = faucetButtons[0]
assert.equal(await faucetLinkButton.getText(), 'RSK Testnet Test Faucet', "screen 'Buy RSK' has incorrect name for faucet link")
await faucetLinkButton.click()
await f.delay(3000)
const [tab0, tab1] = await f.driver.getAllWindowHandles()
await f.driver.switchTo().window(tab1)
const faucetLink = await f.driver.getCurrentUrl()
assert.equal(faucetLink, 'https://faucet.testnet.rsk.co/', 'Incorrect faucet link for RSK network')
await f.driver.close()
await f.driver.switchTo().window(tab0)
const arrow = await f.waitUntilShowUp(elements.buttonArrow)
await arrow.click()
await f.delay(2000)
})
it('opens send transaction screen', async function () {
const sendButton = await f.waitUntilShowUp(screens.main.buttons.sendRSK)
assert.equal(await sendButton.getText(), screens.main.buttons.sendText)
await f.click(sendButton)
})
it('adds recipient address and amount', async function () {
const sendTranscationScreen = await f.waitUntilShowUp(screens.sendTransaction.title)
assert.equal(await sendTranscationScreen.getText(), screens.sendTransaction.titleText, 'Transaction screen has incorrect titlr')
const inputAddress = await f.waitUntilShowUp(screens.sendTransaction.field.address)
const inputAmmount = await f.waitUntilShowUp(screens.sendTransaction.field.amount)
await inputAddress.sendKeys(account1)
await f.clearField(inputAmmount)
await inputAmmount.sendKeys('0.000001')
const button = await f.waitUntilShowUp(screens.sendTransaction.buttonNext)
assert.equal(await button.getText(), 'Next', 'button has incorrect name')
await f.click(button)
})
it('confirms transaction', async function () {
const inputGasLimit = await f.waitUntilShowUp(screens.confirmTransaction.fields.gasLimit)
await f.clearField(inputGasLimit)
await inputGasLimit.sendKeys('31500')
const button = await f.waitUntilShowUp(screens.confirmTransaction.button.submit)
assert.equal(await button.getAttribute('value'), 'Submit', 'button has incorrect name')
await f.click(button)
})
it('finds the transaction in the transactions list', async function () {
const transactionAmount = await f.waitUntilShowUp(screens.main.transactionList)
assert.equal(await transactionAmount.getText(), '<0.001')
})
}
module.exports = RSKNetworkTests

View File

@ -165,6 +165,11 @@ const addCustomToken = async (f, account1, account2) => {
await f.setProvider(NETWORKS.RINKEBY)
assert.equal(await f.assertTokensNotDisplayed(), true, 'tokens are displayed')
})
it('token should not be displayed in RSK network', async () => {
await f.setProvider(NETWORKS.RSK)
assert.equal(await f.assertTokensNotDisplayed(), true, 'tokens are displayed')
})
})
describe.skip('Custom tokens validation ', async () => {
@ -200,6 +205,11 @@ const addCustomToken = async (f, account1, account2) => {
assert(await f.isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in MAINNET')
})
it('can not add inexistent token to RSK mainnet', async () => {
await f.setProvider(NETWORKS.RSK)
assert(await f.isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in RSK mainnet')
})
it('can not add inexistent token to LOCALHOST network', async () => {
await f.setProvider(NETWORKS.LOCALHOST)
assert(await f.isDisabledAddInexistentToken(tokenAddress.slice(0, tokenAddress.length - 2) + '0'), true, 'can add inexistent token in LOCALHOST network')

View File

@ -250,6 +250,11 @@ const addTokeFromSearch = async (f) => {
await f.setProvider(NETWORKS.RINKEBY)
assert.equal(await f.assertTokensNotDisplayed(), true, 'tokens are displayed')
})
it('token should not be displayed in RSK mainnet', async () => {
await f.setProvider(NETWORKS.RSK)
assert.equal(await f.assertTokensNotDisplayed(), true, 'tokens are displayed')
})
})
describe('remove Mainnet\'s tokens', function () {

View File

@ -14,6 +14,7 @@ const { ENVIRONMENT_TYPE_NOTIFICATION } = require('../../app/scripts/lib/enums')
const { POA,
DAI,
POA_SOKOL,
RSK,
CLASSIC } = require('../../app/scripts/controllers/network/enums')
const { hasUnconfirmedTransactions } = require('./helpers/confirm-transaction/util')
const WebcamUtils = require('../lib/webcam-utils')
@ -2014,7 +2015,8 @@ function setProviderType (type) {
const newCoin = type === POA || type === POA_SOKOL ?
'poa' : type === DAI ?
'dai' : type === CLASSIC ?
'etc' : 'eth'
'etc' : type === RSK ?
'rbtc' : 'eth'
background.setCurrentCoin(newCoin, (err, data) => {
if (err) {
log.error(err.stack)