aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/e2e/beta/contract-test/contract.js199
-rw-r--r--test/e2e/beta/drizzle.spec.js25
-rw-r--r--test/e2e/beta/helpers.js17
-rw-r--r--test/e2e/beta/metamask-beta-ui.spec.js41
-rw-r--r--test/integration/lib/mascara-first-time.js2
-rw-r--r--test/unit/app/controllers/preferences-controller-test.js30
-rw-r--r--test/unit/ui/app/reducers/app.spec.js998
-rw-r--r--test/unit/ui/app/reducers/metamask.spec.js576
8 files changed, 1775 insertions, 113 deletions
diff --git a/test/e2e/beta/contract-test/contract.js b/test/e2e/beta/contract-test/contract.js
index 39e7238ae..65fb9377f 100644
--- a/test/e2e/beta/contract-test/contract.js
+++ b/test/e2e/beta/contract-test/contract.js
@@ -28,114 +28,115 @@ The `piggybankContract` is compiled from:
}
*/
-var piggybankContract = web3.eth.contract([{'constant': false, 'inputs': [{'name': 'withdrawAmount', 'type': 'uint256'}], 'name': 'withdraw', 'outputs': [{'name': 'remainingBal', 'type': 'uint256'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'owner', 'outputs': [{'name': '', 'type': 'address'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': false, 'inputs': [], 'name': 'deposit', 'outputs': [{'name': '', 'type': 'uint256'}], 'payable': true, 'stateMutability': 'payable', 'type': 'function'}, {'inputs': [], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'constructor'}])
-const deployButton = document.getElementById('deployButton')
-const depositButton = document.getElementById('depositButton')
-const withdrawButton = document.getElementById('withdrawButton')
-const sendButton = document.getElementById('sendButton')
-const createToken = document.getElementById('createToken')
-const transferTokens = document.getElementById('transferTokens')
-const approveTokens = document.getElementById('approveTokens')
-
-deployButton.addEventListener('click', async function (event) {
- document.getElementById('contractStatus').innerHTML = 'Deploying'
-
- var piggybank = await piggybankContract.new(
- {
- from: web3.eth.accounts[0],
- data: '0x608060405234801561001057600080fd5b5033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000808190555061023b806100686000396000f300608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632e1a7d4d1461005c5780638da5cb5b1461009d578063d0e30db0146100f4575b600080fd5b34801561006857600080fd5b5061008760048036038101908080359060200190929190505050610112565b6040518082815260200191505060405180910390f35b3480156100a957600080fd5b506100b26101d0565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100fc6101f6565b6040518082815260200191505060405180910390f35b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561017057600080fd5b8160008082825403925050819055503373ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f193505050501580156101c5573d6000803e3d6000fd5b506000549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60003460008082825401925050819055506000549050905600a165627a7a72305820f237db3ec816a52589d82512117bc85bc08d3537683ffeff9059108caf3e5d400029',
- gas: '4700000',
- }, function (e, contract) {
- if (e) {
- throw e
- }
- if (typeof contract.address !== 'undefined') {
- console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash)
-
- document.getElementById('contractStatus').innerHTML = 'Deployed'
-
- depositButton.addEventListener('click', function (event) {
- document.getElementById('contractStatus').innerHTML = 'Deposit initiated'
- contract.deposit({ from: web3.eth.accounts[0], value: '0x3782dace9d900000' }, function (result) {
- console.log(result)
- document.getElementById('contractStatus').innerHTML = 'Deposit completed'
+web3.currentProvider.enable().then(() => {
+ var piggybankContract = web3.eth.contract([{'constant': false, 'inputs': [{'name': 'withdrawAmount', 'type': 'uint256'}], 'name': 'withdraw', 'outputs': [{'name': 'remainingBal', 'type': 'uint256'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'owner', 'outputs': [{'name': '', 'type': 'address'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': false, 'inputs': [], 'name': 'deposit', 'outputs': [{'name': '', 'type': 'uint256'}], 'payable': true, 'stateMutability': 'payable', 'type': 'function'}, {'inputs': [], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'constructor'}])
+ const deployButton = document.getElementById('deployButton')
+ const depositButton = document.getElementById('depositButton')
+ const withdrawButton = document.getElementById('withdrawButton')
+ const sendButton = document.getElementById('sendButton')
+ const createToken = document.getElementById('createToken')
+ const transferTokens = document.getElementById('transferTokens')
+ const approveTokens = document.getElementById('approveTokens')
+
+ deployButton.addEventListener('click', async function (event) {
+ document.getElementById('contractStatus').innerHTML = 'Deploying'
+
+ var piggybank = await piggybankContract.new(
+ {
+ from: web3.eth.accounts[0],
+ data: '0x608060405234801561001057600080fd5b5033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000808190555061023b806100686000396000f300608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632e1a7d4d1461005c5780638da5cb5b1461009d578063d0e30db0146100f4575b600080fd5b34801561006857600080fd5b5061008760048036038101908080359060200190929190505050610112565b6040518082815260200191505060405180910390f35b3480156100a957600080fd5b506100b26101d0565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100fc6101f6565b6040518082815260200191505060405180910390f35b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561017057600080fd5b8160008082825403925050819055503373ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f193505050501580156101c5573d6000803e3d6000fd5b506000549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60003460008082825401925050819055506000549050905600a165627a7a72305820f237db3ec816a52589d82512117bc85bc08d3537683ffeff9059108caf3e5d400029',
+ gas: '4700000',
+ }, function (e, contract) {
+ if (e) {
+ throw e
+ }
+ if (typeof contract.address !== 'undefined') {
+ console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash)
+
+ document.getElementById('contractStatus').innerHTML = 'Deployed'
+
+ depositButton.addEventListener('click', function (event) {
+ document.getElementById('contractStatus').innerHTML = 'Deposit initiated'
+ contract.deposit({ from: web3.eth.accounts[0], value: '0x3782dace9d900000' }, function (result) {
+ console.log(result)
+ document.getElementById('contractStatus').innerHTML = 'Deposit completed'
+ })
})
- })
- withdrawButton.addEventListener('click', function (event) {
- contract.withdraw('0xde0b6b3a7640000', { from: web3.eth.accounts[0] }, function (result) {
- console.log(result)
- document.getElementById('contractStatus').innerHTML = 'Withdrawn'
+ withdrawButton.addEventListener('click', function (event) {
+ contract.withdraw('0xde0b6b3a7640000', { from: web3.eth.accounts[0] }, function (result) {
+ console.log(result)
+ document.getElementById('contractStatus').innerHTML = 'Withdrawn'
+ })
})
- })
- }
- })
+ }
+ })
- console.log(piggybank)
-})
+ console.log(piggybank)
+ })
-sendButton.addEventListener('click', function (event) {
- web3.eth.sendTransaction({
- from: web3.eth.accounts[0],
- to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
- value: '0x29a2241af62c0000',
- gas: 21000,
- gasPrice: 20000000000,
- }, (result) => {
- console.log(result)
+ sendButton.addEventListener('click', function (event) {
+ web3.eth.sendTransaction({
+ from: web3.eth.accounts[0],
+ to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
+ value: '0x29a2241af62c0000',
+ gas: 21000,
+ gasPrice: 20000000000,
+ }, (result) => {
+ console.log(result)
+ })
})
-})
-createToken.addEventListener('click', async function (event) {
- var _initialAmount = 100
- var _tokenName = 'TST'
- var _decimalUnits = 0
- var _tokenSymbol = 'TST'
- var humanstandardtokenContract = web3.eth.contract([{'constant': true, 'inputs': [], 'name': 'name', 'outputs': [{'name': '', 'type': 'string'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': false, 'inputs': [{'name': '_spender', 'type': 'address'}, {'name': '_value', 'type': 'uint256'}], 'name': 'approve', 'outputs': [{'name': 'success', 'type': 'bool'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'totalSupply', 'outputs': [{'name': '', 'type': 'uint256'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': false, 'inputs': [{'name': '_from', 'type': 'address'}, {'name': '_to', 'type': 'address'}, {'name': '_value', 'type': 'uint256'}], 'name': 'transferFrom', 'outputs': [{'name': 'success', 'type': 'bool'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'decimals', 'outputs': [{'name': '', 'type': 'uint8'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'version', 'outputs': [{'name': '', 'type': 'string'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': true, 'inputs': [{'name': '_owner', 'type': 'address'}], 'name': 'balanceOf', 'outputs': [{'name': 'balance', 'type': 'uint256'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'symbol', 'outputs': [{'name': '', 'type': 'string'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': false, 'inputs': [{'name': '_to', 'type': 'address'}, {'name': '_value', 'type': 'uint256'}], 'name': 'transfer', 'outputs': [{'name': 'success', 'type': 'bool'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': false, 'inputs': [{'name': '_spender', 'type': 'address'}, {'name': '_value', 'type': 'uint256'}, {'name': '_extraData', 'type': 'bytes'}], 'name': 'approveAndCall', 'outputs': [{'name': 'success', 'type': 'bool'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': true, 'inputs': [{'name': '_owner', 'type': 'address'}, {'name': '_spender', 'type': 'address'}], 'name': 'allowance', 'outputs': [{'name': 'remaining', 'type': 'uint256'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'inputs': [{'name': '_initialAmount', 'type': 'uint256'}, {'name': '_tokenName', 'type': 'string'}, {'name': '_decimalUnits', 'type': 'uint8'}, {'name': '_tokenSymbol', 'type': 'string'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'constructor'}, {'payable': false, 'stateMutability': 'nonpayable', 'type': 'fallback'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': '_from', 'type': 'address'}, {'indexed': true, 'name': '_to', 'type': 'address'}, {'indexed': false, 'name': '_value', 'type': 'uint256'}], 'name': 'Transfer', 'type': 'event'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': '_owner', 'type': 'address'}, {'indexed': true, 'name': '_spender', 'type': 'address'}, {'indexed': false, 'name': '_value', 'type': 'uint256'}], 'name': 'Approval', 'type': 'event'}])
- return humanstandardtokenContract.new(
- _initialAmount,
- _tokenName,
- _decimalUnits,
- _tokenSymbol,
- {
- from: web3.eth.accounts[0],
- data: '0x60806040526040805190810160405280600481526020017f48302e3100000000000000000000000000000000000000000000000000000000815250600690805190602001906200005192919062000143565b503480156200005f57600080fd5b50604051620011f3380380620011f383398101806040528101908080519060200190929190805182019291906020018051906020019092919080518201929190505050836000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508360028190555082600390805190602001906200010492919062000143565b5081600460006101000a81548160ff021916908360ff16021790555080600590805190602001906200013892919062000143565b5050505050620001f2565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200018657805160ff1916838001178555620001b7565b82800160010185558215620001b7579182015b82811115620001b657825182559160200191906001019062000199565b5b509050620001c69190620001ca565b5090565b620001ef91905b80821115620001eb576000816000905550600101620001d1565b5090565b90565b610ff180620002026000396000f3006080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100c1578063095ea7b31461015157806318160ddd146101b657806323b872dd146101e1578063313ce5671461026657806354fd4d501461029757806370a082311461032757806395d89b411461037e578063a9059cbb1461040e578063cae9ca5114610473578063dd62ed3e1461051e575b3480156100bb57600080fd5b50600080fd5b3480156100cd57600080fd5b506100d6610595565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101165780820151818401526020810190506100fb565b50505050905090810190601f1680156101435780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015d57600080fd5b5061019c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610633565b604051808215151515815260200191505060405180910390f35b3480156101c257600080fd5b506101cb610725565b6040518082815260200191505060405180910390f35b3480156101ed57600080fd5b5061024c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061072b565b604051808215151515815260200191505060405180910390f35b34801561027257600080fd5b5061027b6109a4565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102a357600080fd5b506102ac6109b7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102ec5780820151818401526020810190506102d1565b50505050905090810190601f1680156103195780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561033357600080fd5b50610368600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a55565b6040518082815260200191505060405180910390f35b34801561038a57600080fd5b50610393610a9d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103d35780820151818401526020810190506103b8565b50505050905090810190601f1680156104005780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561041a57600080fd5b50610459600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b3b565b604051808215151515815260200191505060405180910390f35b34801561047f57600080fd5b50610504600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610ca1565b604051808215151515815260200191505060405180910390f35b34801561052a57600080fd5b5061057f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f3e565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561062b5780601f106106005761010080835404028352916020019161062b565b820191906000526020600020905b81548152906001019060200180831161060e57829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60025481565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156107f7575081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b80156108035750600082115b1561099857816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905061099d565b600090505b9392505050565b600460009054906101000a900460ff1681565b60068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a4d5780601f10610a2257610100808354040283529160200191610a4d565b820191906000526020600020905b815481529060010190602001808311610a3057829003601f168201915b505050505081565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b335780601f10610b0857610100808354040283529160200191610b33565b820191906000526020600020905b815481529060010190602001808311610b1657829003601f168201915b505050505081565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b8b5750600082115b15610c9657816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610c9b565b600090505b92915050565b600082600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff1660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e01905060405180910390207c01000000000000000000000000000000000000000000000000000000009004338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828051906020019080838360005b83811015610ee2578082015181840152602081019050610ec7565b50505050905090810190601f168015610f0f5780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af1925050501515610f3357600080fd5b600190509392505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a723058200052919e0bc22b5adcd3d320be977df3a1dcc35d1a0160287383ba371900a1c50029',
- gas: '4700000',
- gasPrice: '20000000000',
- }, function (e, contract) {
- console.log(e, contract)
- if (typeof contract.address !== 'undefined') {
- console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash)
-
- document.getElementById('tokenAddress').innerHTML = contract.address
-
- transferTokens.addEventListener('click', function (event) {
- console.log(`event`, event)
- contract.transfer('0x2f318C334780961FB129D2a6c30D0763d9a5C970', '7', {
- from: web3.eth.accounts[0],
- to: contract.address,
- data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a',
- gas: 60000,
- gasPrice: '20000000000',
- }, function (result) {
- console.log('result', result)
+ createToken.addEventListener('click', async function (event) {
+ var _initialAmount = 100
+ var _tokenName = 'TST'
+ var _decimalUnits = 0
+ var _tokenSymbol = 'TST'
+ var humanstandardtokenContract = web3.eth.contract([{'constant': true, 'inputs': [], 'name': 'name', 'outputs': [{'name': '', 'type': 'string'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': false, 'inputs': [{'name': '_spender', 'type': 'address'}, {'name': '_value', 'type': 'uint256'}], 'name': 'approve', 'outputs': [{'name': 'success', 'type': 'bool'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'totalSupply', 'outputs': [{'name': '', 'type': 'uint256'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': false, 'inputs': [{'name': '_from', 'type': 'address'}, {'name': '_to', 'type': 'address'}, {'name': '_value', 'type': 'uint256'}], 'name': 'transferFrom', 'outputs': [{'name': 'success', 'type': 'bool'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'decimals', 'outputs': [{'name': '', 'type': 'uint8'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'version', 'outputs': [{'name': '', 'type': 'string'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': true, 'inputs': [{'name': '_owner', 'type': 'address'}], 'name': 'balanceOf', 'outputs': [{'name': 'balance', 'type': 'uint256'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': true, 'inputs': [], 'name': 'symbol', 'outputs': [{'name': '', 'type': 'string'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'constant': false, 'inputs': [{'name': '_to', 'type': 'address'}, {'name': '_value', 'type': 'uint256'}], 'name': 'transfer', 'outputs': [{'name': 'success', 'type': 'bool'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': false, 'inputs': [{'name': '_spender', 'type': 'address'}, {'name': '_value', 'type': 'uint256'}, {'name': '_extraData', 'type': 'bytes'}], 'name': 'approveAndCall', 'outputs': [{'name': 'success', 'type': 'bool'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': true, 'inputs': [{'name': '_owner', 'type': 'address'}, {'name': '_spender', 'type': 'address'}], 'name': 'allowance', 'outputs': [{'name': 'remaining', 'type': 'uint256'}], 'payable': false, 'stateMutability': 'view', 'type': 'function'}, {'inputs': [{'name': '_initialAmount', 'type': 'uint256'}, {'name': '_tokenName', 'type': 'string'}, {'name': '_decimalUnits', 'type': 'uint8'}, {'name': '_tokenSymbol', 'type': 'string'}], 'payable': false, 'stateMutability': 'nonpayable', 'type': 'constructor'}, {'payable': false, 'stateMutability': 'nonpayable', 'type': 'fallback'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': '_from', 'type': 'address'}, {'indexed': true, 'name': '_to', 'type': 'address'}, {'indexed': false, 'name': '_value', 'type': 'uint256'}], 'name': 'Transfer', 'type': 'event'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': '_owner', 'type': 'address'}, {'indexed': true, 'name': '_spender', 'type': 'address'}, {'indexed': false, 'name': '_value', 'type': 'uint256'}], 'name': 'Approval', 'type': 'event'}])
+ return humanstandardtokenContract.new(
+ _initialAmount,
+ _tokenName,
+ _decimalUnits,
+ _tokenSymbol,
+ {
+ from: web3.eth.accounts[0],
+ data: '0x60806040526040805190810160405280600481526020017f48302e3100000000000000000000000000000000000000000000000000000000815250600690805190602001906200005192919062000143565b503480156200005f57600080fd5b50604051620011f3380380620011f383398101806040528101908080519060200190929190805182019291906020018051906020019092919080518201929190505050836000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508360028190555082600390805190602001906200010492919062000143565b5081600460006101000a81548160ff021916908360ff16021790555080600590805190602001906200013892919062000143565b5050505050620001f2565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200018657805160ff1916838001178555620001b7565b82800160010185558215620001b7579182015b82811115620001b657825182559160200191906001019062000199565b5b509050620001c69190620001ca565b5090565b620001ef91905b80821115620001eb576000816000905550600101620001d1565b5090565b90565b610ff180620002026000396000f3006080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100c1578063095ea7b31461015157806318160ddd146101b657806323b872dd146101e1578063313ce5671461026657806354fd4d501461029757806370a082311461032757806395d89b411461037e578063a9059cbb1461040e578063cae9ca5114610473578063dd62ed3e1461051e575b3480156100bb57600080fd5b50600080fd5b3480156100cd57600080fd5b506100d6610595565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101165780820151818401526020810190506100fb565b50505050905090810190601f1680156101435780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015d57600080fd5b5061019c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610633565b604051808215151515815260200191505060405180910390f35b3480156101c257600080fd5b506101cb610725565b6040518082815260200191505060405180910390f35b3480156101ed57600080fd5b5061024c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061072b565b604051808215151515815260200191505060405180910390f35b34801561027257600080fd5b5061027b6109a4565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102a357600080fd5b506102ac6109b7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102ec5780820151818401526020810190506102d1565b50505050905090810190601f1680156103195780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561033357600080fd5b50610368600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a55565b6040518082815260200191505060405180910390f35b34801561038a57600080fd5b50610393610a9d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103d35780820151818401526020810190506103b8565b50505050905090810190601f1680156104005780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561041a57600080fd5b50610459600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b3b565b604051808215151515815260200191505060405180910390f35b34801561047f57600080fd5b50610504600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610ca1565b604051808215151515815260200191505060405180910390f35b34801561052a57600080fd5b5061057f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f3e565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561062b5780601f106106005761010080835404028352916020019161062b565b820191906000526020600020905b81548152906001019060200180831161060e57829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60025481565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156107f7575081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b80156108035750600082115b1561099857816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905061099d565b600090505b9392505050565b600460009054906101000a900460ff1681565b60068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a4d5780601f10610a2257610100808354040283529160200191610a4d565b820191906000526020600020905b815481529060010190602001808311610a3057829003601f168201915b505050505081565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b335780601f10610b0857610100808354040283529160200191610b33565b820191906000526020600020905b815481529060010190602001808311610b1657829003601f168201915b505050505081565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b8b5750600082115b15610c9657816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610c9b565b600090505b92915050565b600082600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff1660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e01905060405180910390207c01000000000000000000000000000000000000000000000000000000009004338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828051906020019080838360005b83811015610ee2578082015181840152602081019050610ec7565b50505050905090810190601f168015610f0f5780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af1925050501515610f3357600080fd5b600190509392505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a723058200052919e0bc22b5adcd3d320be977df3a1dcc35d1a0160287383ba371900a1c50029',
+ gas: '4700000',
+ gasPrice: '20000000000',
+ }, function (e, contract) {
+ console.log(e, contract)
+ if (typeof contract.address !== 'undefined') {
+ console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash)
+
+ document.getElementById('tokenAddress').innerHTML = contract.address
+
+ transferTokens.addEventListener('click', function (event) {
+ console.log(`event`, event)
+ contract.transfer('0x2f318C334780961FB129D2a6c30D0763d9a5C970', '7', {
+ from: web3.eth.accounts[0],
+ to: contract.address,
+ data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a',
+ gas: 60000,
+ gasPrice: '20000000000',
+ }, function (result) {
+ console.log('result', result)
+ })
})
- })
-
- approveTokens.addEventListener('click', function (event) {
- contract.approve('0x2f318C334780961FB129D2a6c30D0763d9a5C970', '7', {
- from: web3.eth.accounts[0],
- to: contract.address,
- data: '0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005',
- gas: 60000,
- gasPrice: '20000000000',
- }, function (result) {
- console.log(result)
+
+ approveTokens.addEventListener('click', function (event) {
+ contract.approve('0x2f318C334780961FB129D2a6c30D0763d9a5C970', '7', {
+ from: web3.eth.accounts[0],
+ to: contract.address,
+ data: '0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005',
+ gas: 60000,
+ gasPrice: '20000000000',
+ }, function (result) {
+ console.log(result)
+ })
})
- })
- }
- })
+ }
+ })
+ })
})
-
diff --git a/test/e2e/beta/drizzle.spec.js b/test/e2e/beta/drizzle.spec.js
index ff4b4b74d..a9d72a9ba 100644
--- a/test/e2e/beta/drizzle.spec.js
+++ b/test/e2e/beta/drizzle.spec.js
@@ -19,6 +19,7 @@ const {
openNewPage,
verboseReportOnFailure,
waitUntilXWindowHandles,
+ switchToWindowWithTitle,
} = require('./helpers')
describe('MetaMask', function () {
@@ -266,17 +267,31 @@ describe('MetaMask', function () {
})
describe('Drizzle', () => {
- it('should be able to detect our eth address', async () => {
+ let windowHandles
+ let extension
+ let popup
+ let dapp
+
+ it('should be able to connect the account', async () => {
await openNewPage(driver, 'http://127.0.0.1:3000/')
await delay(regularDelayMs)
- await waitUntilXWindowHandles(driver, 2)
- const windowHandles = await driver.getAllWindowHandles()
- const dapp = windowHandles[1]
+ await waitUntilXWindowHandles(driver, 3)
+ windowHandles = await driver.getAllWindowHandles()
+
+ extension = windowHandles[0]
+ popup = await switchToWindowWithTitle(driver, 'MetaMask Notification', windowHandles)
+ dapp = windowHandles.find(handle => handle !== extension && handle !== popup)
- await driver.switchTo().window(dapp)
await delay(regularDelayMs)
+ const approveButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Connect')]`))
+ await approveButton.click()
+ })
+ it('should be able to detect our eth address', async () => {
+ // Check if address exposed
+ await driver.switchTo().window(dapp)
+ await delay(regularDelayMs)
const addressElement = await findElement(driver, By.css(`.pure-u-1-1 h4`))
const addressText = await addressElement.getText()
diff --git a/test/e2e/beta/helpers.js b/test/e2e/beta/helpers.js
index 4055d8155..08416857e 100644
--- a/test/e2e/beta/helpers.js
+++ b/test/e2e/beta/helpers.js
@@ -14,6 +14,7 @@ module.exports = {
loadExtension,
openNewPage,
switchToWindowWithTitle,
+ switchToWindowWithUrlThatMatches,
verboseReportOnFailure,
waitUntilXWindowHandles,
}
@@ -130,3 +131,19 @@ async function assertElementNotPresent (webdriver, driver, by) {
}
assert.ok(!dataTab, 'Found element that should not be present')
}
+
+async function switchToWindowWithUrlThatMatches (driver, regexp, windowHandles) {
+ if (!windowHandles) {
+ windowHandles = await driver.getAllWindowHandles()
+ } else if (windowHandles.length === 0) {
+ throw new Error('No window that matches: ' + regexp)
+ }
+ const firstHandle = windowHandles[0]
+ await driver.switchTo().window(firstHandle)
+ const windowUrl = await driver.getCurrentUrl()
+ if (windowUrl.match(regexp)) {
+ return firstHandle
+ } else {
+ return await switchToWindowWithUrlThatMatches(driver, regexp, windowHandles.slice(1))
+ }
+}
diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js
index 501ff5be5..3bfa1eaf2 100644
--- a/test/e2e/beta/metamask-beta-ui.spec.js
+++ b/test/e2e/beta/metamask-beta-ui.spec.js
@@ -273,6 +273,22 @@ describe('MetaMask', function () {
})
})
+ describe('Enable privacy mode', () => {
+ it('enables privacy mode', async () => {
+ const networkDropdown = await findElement(driver, By.css('.network-name'))
+ await networkDropdown.click()
+ await delay(regularDelayMs)
+
+ const customRpcButton = await findElement(driver, By.xpath(`//span[contains(text(), 'Custom RPC')]`))
+ await customRpcButton.click()
+ await delay(regularDelayMs)
+
+ const privacyToggle = await findElement(driver, By.css('.settings-page__content-row:nth-of-type(10) .settings-page__content-item-col > div'))
+ await privacyToggle.click()
+ await delay(largeDelayMs * 2)
+ })
+ })
+
describe('Log out an log back in', () => {
it('logs out of the account', async () => {
await driver.findElement(By.css('.account-menu__icon')).click()
@@ -415,24 +431,37 @@ describe('MetaMask', function () {
})
describe('Send ETH from dapp', () => {
+ let windowHandles
+ let extension
+ let popup
+ let dapp
+
it('starts a send transaction inside the dapp', async () => {
await openNewPage(driver, 'http://127.0.0.1:8080/')
await delay(regularDelayMs)
- await waitUntilXWindowHandles(driver, 2)
- let windowHandles = await driver.getAllWindowHandles()
- const extension = windowHandles[0]
- const dapp = windowHandles[1]
+ await waitUntilXWindowHandles(driver, 3)
+ windowHandles = await driver.getAllWindowHandles()
+ extension = windowHandles[0]
+ popup = await switchToWindowWithTitle(driver, 'MetaMask Notification', windowHandles)
+ dapp = windowHandles.find(handle => handle !== extension && handle !== popup)
+
+ await delay(regularDelayMs)
+ const approveButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Connect')]`))
+ await approveButton.click()
+ })
+
+ it('initiates a send from the dapp', async () => {
await driver.switchTo().window(dapp)
await delay(regularDelayMs)
const send3eth = await findElement(driver, By.xpath(`//button[contains(text(), 'Send')]`), 10000)
await send3eth.click()
- await delay(regularDelayMs)
+ await delay(5000)
windowHandles = await driver.getAllWindowHandles()
- await driver.switchTo().window(windowHandles[2])
+ await switchToWindowWithTitle(driver, 'MetaMask Notification', windowHandles)
await delay(regularDelayMs)
await assertElementNotPresent(webdriver, driver, By.xpath(`//li[contains(text(), 'Data')]`))
diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js
index 8bbdb4410..6756b83f9 100644
--- a/test/integration/lib/mascara-first-time.js
+++ b/test/integration/lib/mascara-first-time.js
@@ -77,7 +77,7 @@ async function runFirstTimeUsageTest (assert, done) {
assert.ok(lock, 'Lock menu item found')
lock.click()
- await timeout(1000)
+ await timeout(5000)
const pwBox2 = (await findAsync(app, '#password'))[0]
pwBox2.focus()
diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js
index c64c47ae9..473f22f8b 100644
--- a/test/unit/app/controllers/preferences-controller-test.js
+++ b/test/unit/app/controllers/preferences-controller-test.js
@@ -418,7 +418,7 @@ describe('preferences controller', function () {
req.params.options = { address, symbol, decimals, image }
sandbox.stub(preferencesController, '_validateERC20AssetParams').returns(true)
- preferencesController.showWatchAssetUi = async () => {}
+ preferencesController.openPopup = async () => {}
await preferencesController._handleWatchAssetERC20(req.params.options)
const suggested = preferencesController.getSuggestedTokens()
@@ -438,7 +438,7 @@ describe('preferences controller', function () {
req.params.options = { address, symbol, decimals, image }
sandbox.stub(preferencesController, '_validateERC20AssetParams').returns(true)
- preferencesController.showWatchAssetUi = async () => {
+ preferencesController.openPopup = async () => {
await preferencesController.addToken(address, symbol, decimals, image)
}
@@ -453,6 +453,32 @@ describe('preferences controller', function () {
const assetImages = preferencesController.getAssetImages()
assert.ok(assetImages[address], `set image correctly`)
})
+ it('should validate ERC20 asset correctly', async function () {
+ const validateSpy = sandbox.spy(preferencesController._validateERC20AssetParams)
+ try { validateSpy({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABC', decimals: 0}) } catch (e) {}
+ assert.equal(validateSpy.threw(), false, 'correct options object')
+ const validateSpyAddress = sandbox.spy(preferencesController._validateERC20AssetParams)
+ try { validateSpyAddress({symbol: 'ABC', decimals: 0}) } catch (e) {}
+ assert.equal(validateSpyAddress.threw(), true, 'options object with no address')
+ const validateSpySymbol = sandbox.spy(preferencesController._validateERC20AssetParams)
+ try { validateSpySymbol({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', decimals: 0}) } catch (e) {}
+ assert.equal(validateSpySymbol.threw(), true, 'options object with no symbol')
+ const validateSpyDecimals = sandbox.spy(preferencesController._validateERC20AssetParams)
+ try { validateSpyDecimals({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABC'}) } catch (e) {}
+ assert.equal(validateSpyDecimals.threw(), true, 'options object with no decimals')
+ const validateSpyInvalidSymbol = sandbox.spy(preferencesController._validateERC20AssetParams)
+ try { validateSpyInvalidSymbol({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: 0}) } catch (e) {}
+ assert.equal(validateSpyInvalidSymbol.threw(), true, 'options object with invalid symbol')
+ const validateSpyInvalidDecimals1 = sandbox.spy(preferencesController._validateERC20AssetParams)
+ try { validateSpyInvalidDecimals1({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: -1}) } catch (e) {}
+ assert.equal(validateSpyInvalidDecimals1.threw(), true, 'options object with decimals less than zero')
+ const validateSpyInvalidDecimals2 = sandbox.spy(preferencesController._validateERC20AssetParams)
+ try { validateSpyInvalidDecimals2({rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: 38}) } catch (e) {}
+ assert.equal(validateSpyInvalidDecimals2.threw(), true, 'options object with decimals more than 36')
+ const validateSpyInvalidAddress = sandbox.spy(preferencesController._validateERC20AssetParams)
+ try { validateSpyInvalidAddress({rawAddress: '0x123', symbol: 'ABC', decimals: 0}) } catch (e) {}
+ assert.equal(validateSpyInvalidAddress.threw(), true, 'options object with address invalid')
+ })
})
describe('setPasswordForgotten', function () {
diff --git a/test/unit/ui/app/reducers/app.spec.js b/test/unit/ui/app/reducers/app.spec.js
new file mode 100644
index 000000000..bee4963e5
--- /dev/null
+++ b/test/unit/ui/app/reducers/app.spec.js
@@ -0,0 +1,998 @@
+import assert from 'assert'
+import reduceApp from '../../../../../ui/app/reducers/app'
+import * as actions from '../../../../../ui/app/actions'
+
+describe('App State', () => {
+
+ const metamaskState = {
+ metamask: {
+ selectedAddress: '0xAddress',
+ identities: {
+ '0xAddress': {
+ name: 'account 1',
+ address: '0xAddress',
+ },
+ },
+ },
+ }
+
+ it('App init state', () => {
+ const initState = reduceApp(metamaskState, {})
+
+ assert(initState)
+ })
+
+ it('sets networkd dropdown to true', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.NETWORK_DROPDOWN_OPEN,
+ })
+
+ assert.equal(state.networkDropdownOpen, true)
+ })
+
+ it('sets networkd dropdown to false', () => {
+ const dropdown = { networkDropdowopen: true }
+ const state = {...metamaskState, ...dropdown}
+ const newState = reduceApp(state, {
+ type: actions.NETWORK_DROPDOWN_CLOSE,
+ })
+
+ assert.equal(newState.networkDropdownOpen, false)
+ })
+
+ it('opens sidebar', () => {
+ const value = {
+ 'transitionName': 'sidebar-right',
+ 'type': 'wallet-view',
+ 'isOpen': true,
+ }
+ const state = reduceApp(metamaskState, {
+ type: actions.SIDEBAR_OPEN,
+ value,
+ })
+
+ assert.deepEqual(state.sidebar, value)
+ })
+
+ it('closes sidebar', () => {
+ const openSidebar = { sidebar: { isOpen: true }}
+ const state = {...metamaskState, ...openSidebar}
+
+ const newState = reduceApp(state, {
+ type: actions.SIDEBAR_CLOSE,
+ })
+
+ assert.equal(newState.sidebar.isOpen, false)
+ })
+
+ it('opens alert', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.ALERT_OPEN,
+ value: 'test message',
+ })
+
+ assert.equal(state.alertOpen, true)
+ assert.equal(state.alertMessage, 'test message')
+ })
+
+ it('closes alert', () => {
+ const alert = { alertOpen: true, alertMessage: 'test message' }
+ const state = {...metamaskState, ...alert}
+ const newState = reduceApp(state, {
+ type: actions.ALERT_CLOSE,
+ })
+
+ assert.equal(newState.alertOpen, false)
+ assert.equal(newState.alertMessage, null)
+ })
+
+ it('detects qr code data', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.QR_CODE_DETECTED,
+ value: 'qr data',
+ })
+
+ assert.equal(state.qrCodeData, 'qr data')
+ })
+
+ it('opens modal', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.MODAL_OPEN,
+ payload: {
+ name: 'test',
+ },
+ })
+
+ assert.equal(state.modal.open, true)
+ assert.equal(state.modal.modalState.name, 'test')
+ })
+
+ it('closes modal, but moves open modal state to previous modal state', () => {
+ const opensModal = {
+ modal: {
+ open: true,
+ modalState: {
+ name: 'test',
+ },
+ },
+ }
+
+ const state = { ...metamaskState, appState: { ...opensModal } }
+ const newState = reduceApp(state, {
+ type: actions.MODAL_CLOSE,
+ })
+
+
+ assert.equal(newState.modal.open, false)
+ assert.equal(newState.modal.modalState.name, null)
+ })
+
+ it('tansitions forwards', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.TRANSITION_FORWARD,
+ })
+
+ assert.equal(state.transForward, true)
+ })
+
+ it('transition backwards', () => {
+ const transitionForwardState = { transitionForward: true }
+
+ const state = { ...metamaskState, ...transitionForwardState }
+ const newState = reduceApp(state, {
+ type: actions.TRANSITION_BACKWARD,
+ })
+
+ assert.equal(newState.transForward, false)
+ })
+
+ it('shows create vault', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_CREATE_VAULT,
+ })
+
+ assert.equal(state.currentView.name, 'createVault')
+ assert.equal(state.transForward, true)
+ assert.equal(state.warning, null)
+ })
+
+ it('shows restore vault', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_RESTORE_VAULT,
+ })
+
+ assert.equal(state.currentView.name, 'restoreVault')
+ assert.equal(state.transForward, true)
+ assert.equal(state.forgottenPassword, true)
+ })
+
+ it('sets forgot password', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.FORGOT_PASSWORD,
+ value: true,
+ })
+
+ assert.equal(state.currentView.name, 'restoreVault')
+ })
+
+ it('shows init menu', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_INIT_MENU,
+ })
+
+ assert.equal(state.currentView.name, 'accountDetail')
+ assert.equal(state.currentView.context, '0xAddress')
+ })
+
+ it('shows config page', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_CONFIG_PAGE,
+ value: true,
+ })
+
+ assert.equal(state.currentView.name, 'config')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, true)
+ })
+
+ it('shows add token page', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_ADD_TOKEN_PAGE,
+ value: true,
+ })
+
+ assert.equal(state.currentView.name, 'add-token')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, true)
+ })
+
+ it('shows add suggested token page', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_ADD_SUGGESTED_TOKEN_PAGE,
+ value: true,
+ })
+
+ assert.equal(state.currentView.name, 'add-suggested-token')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, true)
+ })
+
+ it('shows import page', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_IMPORT_PAGE,
+ })
+
+ assert.equal(state.currentView.name, 'import-menu')
+ assert.equal(state.transForward, true)
+ assert.equal(state.warning, null)
+ })
+
+ it('shows new account page', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_NEW_ACCOUNT_PAGE,
+ formToSelect: 'context',
+ })
+
+ assert.equal(state.currentView.name, 'new-account-page')
+ assert.equal(state.currentView.context, 'context')
+ assert.equal(state.transForward, true)
+ assert.equal(state.warning, null)
+ })
+
+ it('sets new account form', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SET_NEW_ACCOUNT_FORM,
+ formToSelect: 'context',
+ })
+
+ assert.equal(state.currentView.name, 'accountDetail')
+ assert.equal(state.currentView.context, 'context')
+ })
+
+ it('shows info page', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_INFO_PAGE,
+ })
+
+ assert.equal(state.currentView.name, 'info')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, true)
+ })
+
+ it('creates new vault in progress', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.CREATE_NEW_VAULT_IN_PROGRESS,
+ })
+
+ assert.equal(state.currentView.name, 'createVault')
+ assert.equal(state.currentView.inProgress, true)
+ assert.equal(state.transForward, true)
+ assert.equal(state.isLoading, true)
+ })
+
+ it('shows new vault seed', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_NEW_VAULT_SEED,
+ value: 'test seed words',
+ })
+
+ assert.equal(state.currentView.name, 'createVaultComplete')
+ assert.equal(state.currentView.seedWords, 'test seed words')
+ assert.equal(state.transForward, true)
+ assert.equal(state.isLoading, false)
+ })
+
+ it('shows new account screen', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.NEW_ACCOUNT_SCREEN,
+ })
+
+ assert.equal(state.currentView.name, 'new-account')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, true)
+ })
+
+ it('shows send page', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_SEND_PAGE,
+ })
+
+ assert.equal(state.currentView.name, 'sendTransaction')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, true)
+ assert.equal(state.warning, null)
+ })
+
+ it('shows send token page', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_SEND_TOKEN_PAGE,
+ })
+
+ assert.equal(state.currentView.name, 'sendToken')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, true)
+ assert.equal(state.warning, null)
+ })
+
+ it('shows new keychain', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_NEW_KEYCHAIN,
+ })
+
+ assert.equal(state.currentView.name, 'newKeychain')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, true)
+ })
+
+ it('unlocks Metamask', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.UNLOCK_METAMASK,
+ })
+
+ assert.equal(state.forgottenPassword, null)
+ assert.deepEqual(state.detailView, {})
+ assert.equal(state.transForward, true)
+ assert.equal(state.warning, null)
+ })
+
+ it('locks Metamask', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.LOCK_METAMASK,
+ })
+
+ assert.equal(state.currentView.name, 'accountDetail')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, false)
+ assert.equal(state.warning, null)
+ })
+
+ it('goes back to init menu', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.BACK_TO_INIT_MENU,
+ })
+
+ assert.equal(state.currentView.name, 'InitMenu')
+ assert.equal(state.transForward, false)
+ assert.equal(state.warning, null)
+ assert.equal(state.forgottenPassword, true)
+ })
+
+ it('goes back to unlock view', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.BACK_TO_UNLOCK_VIEW,
+ })
+
+ assert.equal(state.currentView.name, 'UnlockScreen')
+ assert.equal(state.transForward, true)
+ assert.equal(state.warning, null)
+ assert.equal(state.forgottenPassword, false)
+ })
+
+ it('reveals seed words', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.REVEAL_SEED_CONFIRMATION,
+ })
+
+ assert.equal(state.currentView.name, 'reveal-seed-conf')
+ assert.equal(state.transForward, true)
+ assert.equal(state.warning, null)
+ })
+
+ it('sets selected account', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SET_SELECTED_ACCOUNT,
+ value: 'active address',
+ })
+
+ assert.equal(state.activeAddress, 'active address')
+ })
+
+ it('goes home', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.GO_HOME,
+ })
+
+ assert.equal(state.currentView.name, 'accountDetail')
+ assert.equal(state.accountDetail.subview, 'transactions')
+ assert.equal(state.accountDetail.accountExport, 'none')
+ assert.equal(state.accountDetail.privateKey, '')
+ assert.equal(state.transForward, false)
+ assert.equal(state.warning, null)
+
+ })
+
+ it('shows account detail', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_ACCOUNT_DETAIL,
+ value: 'context address',
+ })
+ assert.equal(state.forgottenPassword, null) // default
+ assert.equal(state.currentView.name, 'accountDetail')
+ assert.equal(state.currentView.context, 'context address')
+ assert.equal(state.accountDetail.subview, 'transactions') // default
+ assert.equal(state.accountDetail.accountExport, 'none') // default
+ assert.equal(state.accountDetail.privateKey, '') // default
+ assert.equal(state.transForward, false)
+
+ })
+
+ it('goes back to account detail', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.BACK_TO_ACCOUNT_DETAIL,
+ value: 'context address',
+ })
+ assert.equal(state.forgottenPassword, null) // default
+ assert.equal(state.currentView.name, 'accountDetail')
+ assert.equal(state.currentView.context, 'context address')
+ assert.equal(state.accountDetail.subview, 'transactions') // default
+ assert.equal(state.accountDetail.accountExport, 'none') // default
+ assert.equal(state.accountDetail.privateKey, '') // default
+ assert.equal(state.transForward, false)
+
+ })
+
+ it('shoes account page', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_ACCOUNTS_PAGE,
+ })
+
+ assert.equal(state.currentView.name, 'accounts')
+ assert.equal(state.currentView.seedWords, undefined)
+ assert.equal(state.transForward, true)
+ assert.equal(state.isLoading, false)
+ assert.equal(state.warning, null)
+ assert.equal(state.scrollToBottom, false)
+ assert.equal(state.forgottenPassword, false)
+ })
+
+ it('shows notice', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_NOTICE,
+ })
+
+ assert.equal(state.transForward, true)
+ assert.equal(state.isLoading, false)
+ })
+
+ it('reveals account', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.REVEAL_ACCOUNT,
+ })
+ assert.equal(state.scrollToBottom, true)
+ })
+
+ it('shows confirm tx page', () => {
+ const txs = {
+ unapprovedTxs: {
+ 1: {
+ id: 1,
+ },
+ 2: {
+ id: 2,
+ },
+ },
+ }
+ const oldState = {
+ metamask: {...metamaskState.metamask, ...txs},
+ }
+ const state = reduceApp(oldState, {
+ type: actions.SHOW_CONF_TX_PAGE,
+ id: 2,
+ transForward: false,
+ })
+
+ assert.equal(state.currentView.name, 'confTx')
+ assert.equal(state.currentView.context, 1)
+ assert.equal(state.transForward, false)
+ assert.equal(state.warning, null)
+ assert.equal(state.isLoading, false)
+
+ })
+
+ it('shows confirm msg page', () => {
+ const msgs = {
+ unapprovedMsgs: {
+ 1: {
+ id: 1,
+ },
+ 2: {
+ id: 2,
+ },
+ },
+ }
+
+ const oldState = {
+ metamask: {...metamaskState, ...msgs},
+ }
+
+ const state = reduceApp(oldState, {
+ type: actions.SHOW_CONF_MSG_PAGE,
+ })
+
+ assert.equal(state.currentView.name, 'confTx')
+ assert.equal(state.currentView.context, 0)
+ assert.equal(state.transForward, true)
+ assert.equal(state.warning, null)
+ assert.equal(state.isLoading, false)
+
+ })
+
+ it('completes tx continues to show pending txs current view context', () => {
+ const txs = {
+ unapprovedTxs: {
+ 1: {
+ id: 1,
+ },
+ 2: {
+ id: 2,
+ },
+ },
+ }
+
+ const oldState = {
+ metamask: {...metamaskState, ...txs},
+ }
+
+ const state = reduceApp(oldState, {
+ type: actions.COMPLETED_TX,
+ value: 1,
+ })
+
+ assert.equal(state.currentView.name, 'confTx')
+ assert.equal(state.currentView.context, 0)
+ assert.equal(state.transForward, false)
+ assert.equal(state.warning, null)
+ })
+
+ it('returns to account detail page when no unconf actions completed tx', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.COMPLETED_TX,
+ })
+
+ assert.equal(state.currentView.name, 'accountDetail')
+ assert.equal(state.currentView.context, '0xAddress')
+ assert.equal(state.transForward, false)
+ assert.equal(state.warning, null)
+ assert.equal(state.accountDetail.subview, 'transactions')
+
+ })
+
+ it('proceeds to change current view context in confTx', () => {
+
+ const oldState = {
+ metamask: {metamaskState},
+ appState: {currentView: {context: 0}},
+ }
+
+ const state = reduceApp(oldState, {
+ type: actions.NEXT_TX,
+ })
+
+ assert.equal(state.currentView.name, 'confTx')
+ assert.equal(state.currentView.context, 1)
+ assert.equal(state.warning, null)
+ })
+
+ it('views pending tx', () => {
+ const txs = {
+ unapprovedTxs: {
+ 1: {
+ id: 1,
+ },
+ 2: {
+ id: 2,
+ },
+ },
+ }
+
+
+ const oldState = {
+ metamask: {...metamaskState, ...txs},
+ }
+
+ const state = reduceApp(oldState, {
+ type: actions.VIEW_PENDING_TX,
+ value: 2,
+ })
+
+ assert.equal(state.currentView.name, 'confTx')
+ assert.equal(state.currentView.context, 1)
+ assert.equal(state.warning, null)
+ })
+
+ it('views previous tx', () => {
+ const txs = {
+ unapprovedTxs: {
+ 1: {
+ id: 1,
+ },
+ 2: {
+ id: 2,
+ },
+ },
+ }
+
+
+ const oldState = {
+ metamask: {...metamaskState, ...txs},
+ }
+
+ const state = reduceApp(oldState, {
+ type: actions.VIEW_PENDING_TX,
+ value: 2,
+ })
+
+ assert.equal(state.currentView.name, 'confTx')
+ assert.equal(state.currentView.context, 1)
+ assert.equal(state.warning, null)
+ })
+
+ it('sets error message in confTx view', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.TRANSACTION_ERROR,
+ })
+
+ assert.equal(state.currentView.name, 'confTx')
+ assert.equal(state.currentView.errorMessage, 'There was a problem submitting this transaction.')
+ })
+
+ it('sets default warning when unlock fails', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.UNLOCK_FAILED,
+ })
+
+ assert.equal(state.warning, 'Incorrect password. Try again.')
+ })
+
+ it('sets default warning when unlock fails', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.UNLOCK_FAILED,
+ value: 'errors',
+ })
+
+ assert.equal(state.warning, 'errors')
+ })
+
+ it('sets warning to empty string when unlock succeeds', () => {
+ const errorState = { warning: 'errors' }
+ const oldState = {...metamaskState, ...errorState}
+ const state = reduceApp(oldState, {
+ type: actions.UNLOCK_SUCCEEDED,
+ })
+
+ assert.equal(state.warning, '')
+ })
+
+ it('sets hardware wallet default hd path', () => {
+ const hdPaths = {
+ trezor: "m/44'/60'/0'/0",
+ ledger: "m/44'/60'/0'",
+ }
+ const state = reduceApp(metamaskState, {
+ type: actions.SET_HARDWARE_WALLET_DEFAULT_HD_PATH,
+ value: {
+ device: 'ledger',
+ path: "m/44'/60'/0'",
+ },
+ })
+
+ assert.deepEqual(state.defaultHdPaths, hdPaths)
+ })
+
+ it('shows loading message', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_LOADING,
+ value: 'loading',
+ })
+
+ assert.equal(state.isLoading, true)
+ assert.equal(state.loadingMessage, 'loading')
+ })
+
+ it('hides loading message', () => {
+ const loadingState = { isLoading: true}
+ const oldState = {...metamaskState, ...loadingState}
+
+ const state = reduceApp(oldState, {
+ type: actions.HIDE_LOADING,
+ })
+
+ assert.equal(state.isLoading, false)
+ })
+
+ it('shows sub loading indicator', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_SUB_LOADING_INDICATION,
+ })
+
+ assert.equal(state.isSubLoading, true)
+ })
+
+ it('hides sub loading indicator', () => {
+ const oldState = {...metamaskState, ...oldState}
+ const state = reduceApp(oldState, {
+ type: actions.HIDE_SUB_LOADING_INDICATION,
+ })
+
+ assert.equal(state.isSubLoading, false)
+ })
+
+ it('displays warning', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.DISPLAY_WARNING,
+ value: 'warning',
+ })
+
+ assert.equal(state.isLoading, false)
+ assert.equal(state.warning, 'warning')
+ })
+
+ it('hides warning', () => {
+ const displayWarningState = { warning: 'warning'}
+ const oldState = {...metamaskState, ...displayWarningState}
+ const state = reduceApp(oldState, {
+ type: actions.HIDE_WARNING,
+ })
+
+ assert.equal(state.warning, undefined)
+ })
+
+ it('request to display account export', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.REQUEST_ACCOUNT_EXPORT,
+ })
+
+ assert.equal(state.transForward, true)
+ assert.equal(state.accountDetail.subview, 'export')
+ assert.equal(state.accountDetail.accountExport, 'requested')
+ })
+
+ it('completes account export', () => {
+ const requestAccountExportState = {
+ accountDetail: {
+ subview: 'something',
+ accountExport: 'progress',
+ },
+ }
+ const oldState = {...metamaskState, ...requestAccountExportState}
+ const state = reduceApp(oldState, {
+ type: actions.EXPORT_ACCOUNT,
+ })
+
+ assert.equal(state.accountDetail.subview, 'export')
+ assert.equal(state.accountDetail.accountExport, 'completed')
+ })
+
+ it('shows private key', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_PRIVATE_KEY,
+ value: 'private key',
+ })
+
+ assert.equal(state.accountDetail.subview, 'export')
+ assert.equal(state.accountDetail.accountExport, 'completed')
+ assert.equal(state.accountDetail.privateKey, 'private key')
+ })
+
+ it('shows buy eth view', () => {
+
+ const state = reduceApp(metamaskState, {
+ type: actions.BUY_ETH_VIEW,
+ value: '0xAddress',
+ })
+
+ assert.equal(state.currentView.name, 'buyEth')
+ assert.equal(state.currentView.context, 'accountDetail')
+ assert.equal(state.identity.address, '0xAddress')
+ assert.equal(state.buyView.subview, 'Coinbase')
+ assert.equal(state.buyView.amount, '15.00')
+ assert.equal(state.buyView.buyAddress, '0xAddress')
+ assert.equal(state.buyView.formView.coinbase, true)
+ assert.equal(state.buyView.formView.shapeshift, false)
+ })
+
+ it('shows onboarding subview to buy eth', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.ONBOARDING_BUY_ETH_VIEW,
+ value: '0xAddress',
+ })
+
+ assert.equal(state.currentView.name, 'onboardingBuyEth')
+ assert.equal(state.currentView.context, 'accountDetail')
+ assert.equal(state.identity.address, '0xAddress')
+ })
+
+ it('shows coinbase subview', () => {
+ const appState = {
+ appState: {
+ buyView: {
+ buyAddress: '0xAddress',
+ amount: '12.00',
+ },
+ },
+ }
+ const oldState = {...metamaskState, ...appState}
+ const state = reduceApp(oldState, {
+ type: actions.COINBASE_SUBVIEW,
+ })
+
+ assert.equal(state.buyView.subview, 'Coinbase')
+ assert.equal(state.buyView.formView.coinbase, true)
+ assert.equal(state.buyView.buyAddress, '0xAddress')
+ assert.equal(state.buyView.amount, '12.00')
+ })
+
+ it('shows shapeshift subview', () => {
+ const appState = {
+ appState: {
+ buyView: {
+ buyAddress: '0xAddress',
+ amount: '12.00',
+ },
+ },
+ }
+
+ const marketinfo = {
+ pair: 'BTC_ETH',
+ rate: 28.91191106,
+ minerFee: 0.0022,
+ limit: 0.76617432,
+ minimum: 0.00015323,
+ maxLimit: 0.76617432,
+ }
+
+ const coinOptions = {
+ BTC: {
+ symbol: 'BTC',
+ name: 'Bitcoin',
+ image: 'https://shapeshift.io/images/coins/bitcoin.png',
+ imageSmall: 'https://shapeshift.io/images/coins-sm/bitcoin.png',
+ status: 'available',
+ minerFee: 0.00025,
+ },
+ }
+
+ const oldState = {...metamaskState, ...appState}
+
+ const state = reduceApp(oldState, {
+ type: actions.SHAPESHIFT_SUBVIEW,
+ value: {
+ marketinfo,
+ coinOptions,
+ },
+ })
+
+ assert.equal(state.buyView.subview, 'ShapeShift')
+ assert.equal(state.buyView.formView.shapeshift, true)
+ assert.deepEqual(state.buyView.formView.marketinfo, marketinfo)
+ assert.deepEqual(state.buyView.formView.coinOptions, coinOptions)
+ assert.equal(state.buyView.buyAddress, '0xAddress')
+ assert.equal(state.buyView.amount, '12.00')
+ })
+
+ it('updates pair', () => {
+ const coinOptions = {
+ BTC: {
+ symbol: 'BTC',
+ name: 'Bitcoin',
+ image: 'https://shapeshift.io/images/coins/bitcoin.png',
+ imageSmall: 'https://shapeshift.io/images/coins-sm/bitcoin.png',
+ status: 'available',
+ minerFee: 0.00025,
+ },
+ }
+
+ const appState = {
+ appState: {
+ buyView: {
+ buyAddress: '0xAddress',
+ amount: '12.00',
+ formView: {
+ coinOptions,
+ },
+ },
+ },
+ }
+
+ const marketinfo = {
+ pair: 'BTC_ETH',
+ rate: 28.91191106,
+ minerFee: 0.0022,
+ limit: 0.76617432,
+ minimum: 0.00015323,
+ maxLimit: 0.76617432,
+ }
+
+ const oldState = {...metamaskState, ...appState}
+
+ const state = reduceApp(oldState, {
+ type: actions.PAIR_UPDATE,
+ value: {
+ marketinfo,
+ },
+ })
+
+ assert.equal(state.buyView.subview, 'ShapeShift')
+ assert.equal(state.buyView.formView.shapeshift, true)
+ assert.deepEqual(state.buyView.formView.marketinfo, marketinfo)
+ assert.deepEqual(state.buyView.formView.coinOptions, coinOptions)
+ assert.equal(state.buyView.buyAddress, '0xAddress')
+ assert.equal(state.buyView.amount, '12.00')
+ })
+
+ it('shows QR', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SHOW_QR,
+ value: {
+ message: 'message',
+ data: 'data',
+ },
+ })
+
+ assert.equal(state.qrRequested, true)
+ assert.equal(state.transForward, true)
+ assert.equal(state.Qr.message, 'message')
+ assert.equal(state.Qr.data, 'data')
+ })
+
+ it('shows qr view', () => {
+ const appState = {
+ appState: {
+ currentView: {
+ context: 'accounts',
+ },
+ },
+ }
+
+ const oldState = {...metamaskState, ...appState}
+ const state = reduceApp(oldState, {
+ type: actions.SHOW_QR_VIEW,
+ value: {
+ message: 'message',
+ data: 'data',
+ },
+ })
+
+ assert.equal(state.currentView.name, 'qr')
+ assert.equal(state.currentView.context, 'accounts')
+ assert.equal(state.transForward, true)
+ assert.equal(state.Qr.message, 'message')
+ assert.equal(state.Qr.data, 'data')
+ })
+
+ it('set mouse user state', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SET_MOUSE_USER_STATE,
+ value: true,
+ })
+
+ assert.equal(state.isMouseUser, true)
+ })
+
+ it('sets gas loading', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.GAS_LOADING_STARTED,
+ })
+
+ assert.equal(state.gasIsLoading, true)
+ })
+
+ it('unsets gas loading', () => {
+ const gasLoadingState = { gasIsLoading: true }
+ const oldState = {...metamaskState, ...gasLoadingState}
+ const state = reduceApp(oldState, {
+ type: actions.GAS_LOADING_FINISHED,
+ })
+
+ assert.equal(state.gasIsLoading, false)
+ })
+
+ it('sets network nonce', () => {
+ const state = reduceApp(metamaskState, {
+ type: actions.SET_NETWORK_NONCE,
+ value: '33',
+ })
+
+ assert.equal(state.networkNonce, '33')
+ })
+})
diff --git a/test/unit/ui/app/reducers/metamask.spec.js b/test/unit/ui/app/reducers/metamask.spec.js
new file mode 100644
index 000000000..e1a50eef2
--- /dev/null
+++ b/test/unit/ui/app/reducers/metamask.spec.js
@@ -0,0 +1,576 @@
+import assert from 'assert'
+import reduceMetamask from '../../../../../ui/app/reducers/metamask'
+import * as actions from '../../../../../ui/app/actions'
+
+describe('MetaMask Reducers', () => {
+
+ it('init state', () => {
+ const initState = reduceMetamask({metamask:{}}, {})
+ assert(initState)
+ })
+
+ it('sets revealing seed to true and adds seed words to new state', () => {
+ const seedWordsState = reduceMetamask({}, {
+ type: actions.SHOW_NEW_VAULT_SEED,
+ value: 'test seed words',
+ })
+
+ assert.equal(seedWordsState.seedWords, 'test seed words')
+ assert.equal(seedWordsState.isRevealingSeedWords, true)
+ })
+
+ it('shows account page', () => {
+ const seedWordsState = {
+ metamask: {
+ seedwords: 'test seed words',
+ isRevealing: true,
+ },
+ }
+
+ const state = reduceMetamask(seedWordsState, {
+ type: actions.SHOW_ACCOUNTS_PAGE,
+ })
+
+ assert.equal(state.seedWords, undefined)
+ assert.equal(state.isRevealingSeedWords, false)
+ })
+
+ it('shows notice', () => {
+ const notice = {
+ id: 0,
+ read: false,
+ date: 'Date',
+ title: 'Title',
+ body: 'Body',
+ }
+
+ const state = reduceMetamask({}, {
+ type: actions.SHOW_NOTICE,
+ value: notice,
+ })
+
+ assert.equal(state.noActiveNotices, false)
+ assert.equal(state.nextUnreadNotice, notice)
+ })
+
+ it('clears notice', () => {
+
+ const notice = {
+ id: 0,
+ read: false,
+ date: 'Date',
+ title: 'Title',
+ body: 'Body',
+ }
+
+ const noticesState = {
+ metamask: {
+ noActiveNotices: false,
+ nextUnreadNotice: notice,
+ },
+ }
+
+ const state = reduceMetamask(noticesState, {
+ type: actions.CLEAR_NOTICES,
+ })
+
+ assert.equal(state.noActiveNotices, true)
+ assert.equal(state.nextUnreadNotice, null)
+ })
+
+ it('unlocks MetaMask', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UNLOCK_METAMASK,
+ value: 'test address',
+ })
+
+ assert.equal(state.isUnlocked, true)
+ assert.equal(state.isInitialized, true)
+ assert.equal(state.selectedAddress, 'test address')
+ })
+
+ it('locks MetaMask', () => {
+ const unlockMetaMaskState = {
+ metamask: {
+ isUnlocked: true,
+ isInitialzed: false,
+ selectedAddress: 'test address',
+ },
+ }
+ const lockMetaMask = reduceMetamask(unlockMetaMaskState, {
+ type: actions.LOCK_METAMASK,
+ })
+
+ assert.equal(lockMetaMask.isUnlocked, false)
+ })
+
+ it('sets frequent rpc list', () => {
+ const state = reduceMetamask({}, {
+ type: actions.SET_RPC_LIST,
+ value: 'https://custom.rpc',
+ })
+
+ assert.equal(state.frequentRpcList, 'https://custom.rpc')
+ })
+
+ it('sets rpc target', () => {
+ const state = reduceMetamask({}, {
+ type: actions.SET_RPC_TARGET,
+ value: 'https://custom.rpc',
+ })
+
+ assert.equal(state.provider.rpcTarget, 'https://custom.rpc')
+ })
+
+ it('sets provider type', () => {
+ const state = reduceMetamask({}, {
+ type: actions.SET_PROVIDER_TYPE,
+ value: 'provider type',
+ })
+
+ assert.equal(state.provider.type, 'provider type')
+ })
+
+ describe('CompletedTx', () => {
+ const oldState = {
+ metamask: {
+ unapprovedTxs: {
+ 1: {
+ id: 1,
+ time: 1538495996507,
+ status: 'unapproved',
+ metamaskNetworkId: 4,
+ loadingDefaults: false,
+ txParams: {
+ from: '0xAddress',
+ to: '0xAddress2',
+ value: '0x16345785d8a0000',
+ gas: '0x5208',
+ gasPrice: '0x3b9aca00',
+ },
+ type: 'standard',
+ },
+ 2: {
+ test: 'Should persist',
+ },
+ },
+ unapprovedMsgs: {
+ 1: {
+ id: 2,
+ msgParams: {
+ from: '0xAddress',
+ data: '0xData',
+ origin: 'test origin',
+ },
+ time: 1538498521717,
+ status: 'unapproved',
+ type: 'eth_sign',
+ },
+ 2: {
+ test: 'Should Persist',
+ },
+ },
+ },
+ }
+
+ it('removes tx from new state if completed in action.', () => {
+
+ const state = reduceMetamask(oldState, {
+ type: actions.COMPLETED_TX,
+ id: 1,
+ })
+
+ assert.equal(Object.keys(state.unapprovedTxs).length, 1)
+ assert.equal(state.unapprovedTxs[2].test, 'Should persist')
+ })
+
+ it('removes msg from new state if completed id in action', () => {
+ const state = reduceMetamask(oldState, {
+ type: actions.COMPLETED_TX,
+ id: 1,
+ })
+
+ assert.equal(Object.keys(state.unapprovedMsgs).length, 1)
+ assert.equal(state.unapprovedTxs[2].test, 'Should persist')
+ })
+ })
+
+ it('shows new vault seed words and sets isRevealingSeedWords to true', () => {
+ const showNewVaultSeedState = reduceMetamask({}, {
+ type: actions.SHOW_NEW_VAULT_SEED,
+ value: 'test seed words',
+ })
+
+ assert.equal(showNewVaultSeedState.isRevealingSeedWords, true)
+ assert.equal(showNewVaultSeedState.seedWords, 'test seed words')
+ })
+
+ it('shows account detail', () => {
+
+ const state = reduceMetamask({}, {
+ type: actions.SHOW_ACCOUNT_DETAIL,
+ value: 'test address',
+ })
+
+ assert.equal(state.isUnlocked, true)
+ assert.equal(state.isInitialized, true)
+ assert.equal(state.selectedAddress, 'test address')
+ })
+
+ it('sets select ', () => {
+ const state = reduceMetamask({}, {
+ type: actions.SET_SELECTED_TOKEN,
+ value: 'test token',
+ })
+
+ assert.equal(state.selectedTokenAddress, 'test token')
+ })
+
+ it('sets account label', () => {
+ const state = reduceMetamask({}, {
+ type: actions.SET_ACCOUNT_LABEL,
+ value: {
+ account: 'test account',
+ label: 'test label',
+ },
+ })
+
+ assert.deepEqual(state.identities, { 'test account': { name: 'test label' } })
+ })
+
+ it('sets current fiat', () => {
+ const value = {
+ currentCurrency: 'yen',
+ conversionRate: 3.14,
+ conversionDate: new Date(2018, 9),
+ }
+
+ const state = reduceMetamask({}, {
+ type: actions.SET_CURRENT_FIAT,
+ value,
+ })
+
+ assert.equal(state.currentCurrency, value.currentCurrency)
+ assert.equal(state.conversionRate, value.conversionRate)
+ assert.equal(state.conversionDate, value.conversionDate)
+ })
+
+ it('updates tokens', () => {
+ const newTokens = {
+ 'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
+ 'decimals': 18,
+ 'symbol': 'META',
+ }
+
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_TOKENS,
+ newTokens,
+ })
+
+ assert.deepEqual(state.tokens, newTokens)
+ })
+
+ it('updates send gas limit', () => {
+
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_GAS_LIMIT,
+ value: '0xGasLimit',
+ })
+
+ assert.equal(state.send.gasLimit, '0xGasLimit')
+ })
+
+ it('updates send gas price', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_GAS_PRICE,
+ value: '0xGasPrice',
+ })
+
+ assert.equal(state.send.gasPrice, '0xGasPrice')
+ })
+
+ it('toggles account menu ', () => {
+ const state = reduceMetamask({}, {
+ type: actions.TOGGLE_ACCOUNT_MENU,
+ })
+
+ assert.equal(state.isAccountMenuOpen, true)
+ })
+
+ it('updates gas total', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_GAS_TOTAL,
+ value: '0xGasTotal',
+ })
+
+ assert.equal(state.send.gasTotal, '0xGasTotal')
+ })
+
+ it('updates send token balance', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_SEND_TOKEN_BALANCE,
+ value: '0xTokenBalance',
+ })
+
+ assert.equal(state.send.tokenBalance, '0xTokenBalance')
+ })
+
+ it('updates data', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_SEND_HEX_DATA,
+ value: '0xData',
+ })
+
+ assert.equal(state.send.data, '0xData')
+ })
+
+ it('updates send to', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_SEND_TO,
+ value: {
+ to: '0xAddress',
+ nickname: 'nickname',
+ },
+ })
+
+ assert.equal(state.send.to, '0xAddress')
+ assert.equal(state.send.toNickname, 'nickname')
+ })
+
+ it('update send from', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_SEND_FROM,
+ value: '0xAddress',
+ })
+
+ assert.equal(state.send.from, '0xAddress')
+ })
+
+ it('update send amount', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_SEND_AMOUNT,
+ value: '0xAmount',
+ })
+
+ assert.equal(state.send.amount, '0xAmount')
+ })
+
+ it('update send memo', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_SEND_MEMO,
+ value: '0xMemo',
+ })
+
+ assert.equal(state.send.memo, '0xMemo')
+ })
+
+ it('updates max mode', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_MAX_MODE,
+ value: true,
+ })
+
+ assert.equal(state.send.maxModeOn, true)
+ })
+
+ it('update send', () => {
+ const value = {
+ gasLimit: '0xGasLimit',
+ gasPrice: '0xGasPrice',
+ gasTotal: '0xGasTotal',
+ tokenBalance: '0xBalance',
+ from: '0xAddress',
+ to: '0xAddress',
+ toNickname: '',
+ maxModeOn: false,
+ amount: '0xAmount',
+ memo: '0xMemo',
+ errors: {},
+ editingTransactionId: 22,
+ forceGasMin: '0xGas',
+ }
+
+ const sendState = reduceMetamask({}, {
+ type: actions.UPDATE_SEND,
+ value,
+ })
+
+ assert.deepEqual(sendState.send, value)
+ })
+
+ it('clears send', () => {
+ const initStateSend = {
+ send:
+ { gasLimit: null,
+ gasPrice: null,
+ gasTotal: null,
+ tokenBalance: null,
+ from: '',
+ to: '',
+ amount: '0x0',
+ memo: '',
+ errors: {},
+ maxModeOn: false,
+ editingTransactionId: null,
+ forceGasMin: null,
+ toNickname: '' },
+ }
+
+ const sendState = {
+ send: {
+ gasLimit: '0xGasLimit',
+ gasPrice: '0xGasPrice',
+ gasTotal: '0xGasTotal',
+ tokenBalance: '0xBalance',
+ from: '0xAddress',
+ to: '0xAddress',
+ toNickname: '',
+ maxModeOn: false,
+ amount: '0xAmount',
+ memo: '0xMemo',
+ errors: {},
+ editingTransactionId: 22,
+ forceGasMin: '0xGas',
+ },
+ }
+
+
+ const state = reduceMetamask(sendState, {
+ type: actions.CLEAR_SEND,
+ })
+
+ assert.deepEqual(state.send, initStateSend.send)
+ })
+
+ it('updates value of tx by id', () => {
+ const oldState = {
+ metamask: {
+ selectedAddressTxList: [
+ {
+ id: 1,
+ txParams: 'foo',
+ },
+ ],
+ },
+ }
+
+ const state = reduceMetamask(oldState, {
+ type: actions.UPDATE_TRANSACTION_PARAMS,
+ id: 1,
+ value: 'bar',
+ })
+
+ assert.equal(state.selectedAddressTxList[0].txParams, 'bar')
+ })
+
+ it('updates pair for shapeshift', () => {
+ const state = reduceMetamask({}, {
+ type: actions.PAIR_UPDATE,
+ value: {
+ marketinfo: {
+ pair: 'test pair',
+ foo: 'bar',
+ },
+ },
+ })
+ assert.equal(state.tokenExchangeRates['test pair'].pair, 'test pair')
+ })
+
+ it('upates pair and coin options for shapeshift subview', () => {
+ const state = reduceMetamask({}, {
+ type: actions.SHAPESHIFT_SUBVIEW,
+ value: {
+ marketinfo: {
+ pair: 'test pair',
+ },
+ coinOptions: {
+ foo: 'bar',
+ },
+ },
+ })
+
+ assert.equal(state.coinOptions.foo, 'bar')
+ assert.equal(state.tokenExchangeRates['test pair'].pair, 'test pair')
+ })
+
+ it('sets blockies', () => {
+ const state = reduceMetamask({}, {
+ type: actions.SET_USE_BLOCKIE,
+ value: true,
+ })
+
+ assert.equal(state.useBlockie, true)
+ })
+
+ it('updates feature flag', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_FEATURE_FLAGS,
+ value: {
+ betaUI: true,
+ skipAnnounceBetaUI: true,
+ },
+ })
+
+ assert.equal(state.featureFlags.betaUI, true)
+ assert.equal(state.featureFlags.skipAnnounceBetaUI, true)
+ })
+
+ it('updates network endpoint type', () => {
+ const state = reduceMetamask({}, {
+ type: actions.UPDATE_NETWORK_ENDPOINT_TYPE,
+ value: 'endpoint',
+ })
+
+ assert.equal(state.networkEndpointType, 'endpoint')
+ })
+
+ it('close welcome screen', () => {
+ const state = reduceMetamask({}, {
+ type: actions.CLOSE_WELCOME_SCREEN,
+ })
+
+ assert.equal(state.welcomeScreenSeen, true)
+ })
+
+ it('sets current locale', () => {
+ const state = reduceMetamask({}, {
+ type: actions.SET_CURRENT_LOCALE,
+ value: 'ge',
+ })
+
+ assert.equal(state.currentLocale, 'ge')
+ })
+
+ it('sets pending tokens ', () => {
+ const payload = {
+ 'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
+ 'decimals': 18,
+ 'symbol': 'META',
+ }
+
+ const pendingTokensState = reduceMetamask({}, {
+ type: actions.SET_PENDING_TOKENS,
+ payload,
+ })
+
+ assert.deepEqual(pendingTokensState.pendingTokens, payload)
+ })
+
+ it('clears pending tokens', () => {
+ const payload = {
+ 'address': '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
+ 'decimals': 18,
+ 'symbol': 'META',
+ }
+
+ const pendingTokensState = {
+ pendingTokens: payload,
+ }
+
+ const state = reduceMetamask(pendingTokensState, {
+ type: actions.CLEAR_PENDING_TOKENS,
+ })
+
+ assert.deepEqual(state.pendingTokens, {})
+ })
+})