diff options
author | Vimal <vtiwari@coinswitch.co> | 2018-11-12 20:20:37 +0800 |
---|---|---|
committer | Vimal <vtiwari@coinswitch.co> | 2018-11-12 20:20:37 +0800 |
commit | 6bb92a8672edf23465fb109c8966d2e56500ea86 (patch) | |
tree | 6f5c4e348fb58fcf23b27278ffae1c1b912ad08e /test | |
parent | 82b11b69a5dea38a4a036096528354a5a291a447 (diff) | |
parent | da1036f2c4b20748407b7fa89b60df5e321fcab7 (diff) | |
download | tangerine-wallet-browser-6bb92a8672edf23465fb109c8966d2e56500ea86.tar.gz tangerine-wallet-browser-6bb92a8672edf23465fb109c8966d2e56500ea86.tar.zst tangerine-wallet-browser-6bb92a8672edf23465fb109c8966d2e56500ea86.zip |
merging upstream branch
Diffstat (limited to 'test')
21 files changed, 2212 insertions, 386 deletions
diff --git a/test/data/mock-state.json b/test/data/mock-state.json index 7e083c60e..8deff5531 100644 --- a/test/data/mock-state.json +++ b/test/data/mock-state.json @@ -111,7 +111,9 @@ "0x108cf70c7d384c552f42c07c41c0e1e46d77ea0d": 0.00039345803819379796, "0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5": 0.00008189274407698049 }, + "ticker": "ETH", "currentCurrency": "usd", + "nativeCurrency": "ETH", "conversionRate": 556.12, "addressBook": [ { @@ -1248,4 +1250,4 @@ "context": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc" } } -}
\ No newline at end of file +} 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/from-import-beta-ui.spec.js b/test/e2e/beta/from-import-beta-ui.spec.js index 32aaa29a6..d2c3f8958 100644 --- a/test/e2e/beta/from-import-beta-ui.spec.js +++ b/test/e2e/beta/from-import-beta-ui.spec.js @@ -286,7 +286,7 @@ describe('Using MetaMask with an existing account', function () { await delay(regularDelayMs) const inputAddress = await findElement(driver, By.css('input[placeholder="Recipient Address"]')) - const inputAmount = await findElement(driver, By.css('.currency-display__input')) + const inputAmount = await findElement(driver, By.css('.unit-input__input')) await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970') await inputAmount.sendKeys('1') @@ -319,7 +319,7 @@ describe('Using MetaMask with an existing account', function () { const txValues = await findElements(driver, By.css('.transaction-list-item__amount--primary')) assert.equal(txValues.length, 1) - assert.equal(await txValues[0].getText(), '-1 ETH') + assert.ok(/-1\s*ETH/.test(await txValues[0].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-responsive-ui.spec.js b/test/e2e/beta/metamask-beta-responsive-ui.spec.js new file mode 100644 index 000000000..b93563b25 --- /dev/null +++ b/test/e2e/beta/metamask-beta-responsive-ui.spec.js @@ -0,0 +1,360 @@ +const path = require('path') +const assert = require('assert') +const webdriver = require('selenium-webdriver') +const { By, until } = webdriver +const { + delay, + buildChromeWebDriver, + buildFirefoxWebdriver, + installWebExt, + getExtensionIdChrome, + getExtensionIdFirefox, +} = require('../func') +const { + checkBrowserForConsoleErrors, + closeAllWindowHandlesExcept, + findElement, + findElements, + loadExtension, + verboseReportOnFailure, +} = require('./helpers') + +describe('MetaMask', function () { + let extensionId + let driver + + const testSeedPhrase = 'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent' + const tinyDelayMs = 200 + const regularDelayMs = tinyDelayMs * 2 + const largeDelayMs = regularDelayMs * 2 + + this.timeout(0) + this.bail(true) + + before(async function () { + switch (process.env.SELENIUM_BROWSER) { + case 'chrome': { + const extPath = path.resolve('dist/chrome') + driver = buildChromeWebDriver(extPath, { responsive: true }) + extensionId = await getExtensionIdChrome(driver) + await driver.get(`chrome-extension://${extensionId}/popup.html`) + break + } + case 'firefox': { + const extPath = path.resolve('dist/firefox') + driver = buildFirefoxWebdriver({ responsive: true }) + await installWebExt(driver, extPath) + await delay(700) + extensionId = await getExtensionIdFirefox(driver) + await driver.get(`moz-extension://${extensionId}/popup.html`) + } + } + }) + + afterEach(async function () { + if (process.env.SELENIUM_BROWSER === 'chrome') { + const errors = await checkBrowserForConsoleErrors(driver) + if (errors.length) { + const errorReports = errors.map(err => err.message) + const errorMessage = `Errors found in browser console:\n${errorReports.join('\n')}` + console.error(new Error(errorMessage)) + } + } + if (this.currentTest.state === 'failed') { + await verboseReportOnFailure(driver, this.currentTest) + } + }) + + after(async function () { + await driver.quit() + }) + + describe('New UI setup', async function () { + it('switches to first tab', async function () { + await delay(tinyDelayMs) + const [firstTab] = await driver.getAllWindowHandles() + await driver.switchTo().window(firstTab) + await delay(regularDelayMs) + }) + + it('selects the new UI option', async () => { + try { + const overlay = await findElement(driver, By.css('.full-flex-height')) + await driver.wait(until.stalenessOf(overlay)) + } catch (e) {} + + let button + try { + button = await findElement(driver, By.xpath("//button[contains(text(), 'Try it now')]")) + } catch (e) { + await loadExtension(driver, extensionId) + await delay(largeDelayMs) + button = await findElement(driver, By.xpath("//button[contains(text(), 'Try it now')]")) + } + await button.click() + await delay(regularDelayMs) + + // Close all other tabs + const [tab0, tab1, tab2] = await driver.getAllWindowHandles() + await driver.switchTo().window(tab0) + await delay(tinyDelayMs) + + let selectedUrl = await driver.getCurrentUrl() + await delay(tinyDelayMs) + if (tab0 && selectedUrl.match(/popup.html/)) { + await closeAllWindowHandlesExcept(driver, tab0) + } else if (tab1) { + await driver.switchTo().window(tab1) + selectedUrl = await driver.getCurrentUrl() + await delay(tinyDelayMs) + if (selectedUrl.match(/popup.html/)) { + await closeAllWindowHandlesExcept(driver, tab1) + } else if (tab2) { + await driver.switchTo().window(tab2) + selectedUrl = await driver.getCurrentUrl() + selectedUrl.match(/popup.html/) && await closeAllWindowHandlesExcept(driver, tab2) + } + } else { + throw new Error('popup.html not found') + } + await delay(regularDelayMs) + const [appTab] = await driver.getAllWindowHandles() + await driver.switchTo().window(appTab) + await delay(tinyDelayMs) + + await loadExtension(driver, extensionId) + await delay(regularDelayMs) + + const continueBtn = await findElement(driver, By.css('.welcome-screen__button')) + await continueBtn.click() + await delay(regularDelayMs) + }) + }) + + describe('Going through the first time flow', () => { + it('accepts a secure password', async () => { + const passwordBox = await findElement(driver, By.css('.create-password #create-password')) + const passwordBoxConfirm = await findElement(driver, By.css('.create-password #confirm-password')) + const button = await findElement(driver, By.css('.create-password button')) + + await passwordBox.sendKeys('correct horse battery staple') + await passwordBoxConfirm.sendKeys('correct horse battery staple') + await button.click() + await delay(regularDelayMs) + }) + + it('clicks through the unique image screen', async () => { + const nextScreen = await findElement(driver, By.css('.unique-image button')) + await nextScreen.click() + await delay(regularDelayMs) + }) + + it('clicks through the ToS', async () => { + // terms of use + const canClickThrough = await driver.findElement(By.css('.tou button')).isEnabled() + assert.equal(canClickThrough, false, 'disabled continue button') + const bottomOfTos = await findElement(driver, By.linkText('Attributions')) + await driver.executeScript('arguments[0].scrollIntoView(true)', bottomOfTos) + await delay(regularDelayMs) + const acceptTos = await findElement(driver, By.css('.tou button')) + driver.wait(until.elementIsEnabled(acceptTos)) + await acceptTos.click() + await delay(regularDelayMs) + }) + + it('clicks through the privacy notice', async () => { + // privacy notice + const nextScreen = await findElement(driver, By.css('.tou button')) + await nextScreen.click() + await delay(regularDelayMs) + }) + + it('clicks through the phishing notice', async () => { + // phishing notice + const noticeElement = await driver.findElement(By.css('.markdown')) + await driver.executeScript('arguments[0].scrollTop = arguments[0].scrollHeight', noticeElement) + await delay(regularDelayMs) + const nextScreen = await findElement(driver, By.css('.tou button')) + await nextScreen.click() + await delay(regularDelayMs) + }) + + let seedPhrase + + it('reveals the seed phrase', async () => { + const byRevealButton = By.css('.backup-phrase__secret-blocker .backup-phrase__reveal-button') + await driver.wait(until.elementLocated(byRevealButton, 10000)) + const revealSeedPhraseButton = await findElement(driver, byRevealButton, 10000) + await revealSeedPhraseButton.click() + await delay(regularDelayMs) + + seedPhrase = await driver.findElement(By.css('.backup-phrase__secret-words')).getText() + assert.equal(seedPhrase.split(' ').length, 12) + await delay(regularDelayMs) + + const nextScreen = await findElement(driver, By.css('.backup-phrase button')) + await nextScreen.click() + await delay(regularDelayMs) + }) + + async function clickWordAndWait (word) { + const xpathClass = 'backup-phrase__confirm-seed-option backup-phrase__confirm-seed-option--unselected' + const xpath = `//button[@class='${xpathClass}' and contains(text(), '${word}')]` + const word0 = await findElement(driver, By.xpath(xpath), 10000) + + await word0.click() + await delay(tinyDelayMs) + } + + async function retypeSeedPhrase (words, wasReloaded, count = 0) { + try { + if (wasReloaded) { + const byRevealButton = By.css('.backup-phrase__secret-blocker .backup-phrase__reveal-button') + await driver.wait(until.elementLocated(byRevealButton, 10000)) + const revealSeedPhraseButton = await findElement(driver, byRevealButton, 10000) + await revealSeedPhraseButton.click() + await delay(regularDelayMs) + + const nextScreen = await findElement(driver, By.css('.backup-phrase button')) + await nextScreen.click() + await delay(regularDelayMs) + } + + for (let i = 0; i < 12; i++) { + await clickWordAndWait(words[i]) + } + } catch (e) { + if (count > 2) { + throw e + } else { + await loadExtension(driver, extensionId) + await retypeSeedPhrase(words, true, count + 1) + } + } + } + + it('can retype the seed phrase', async () => { + const words = seedPhrase.split(' ') + + await retypeSeedPhrase(words) + + const confirm = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`)) + await confirm.click() + await delay(regularDelayMs) + }) + + it('clicks through the deposit modal', async () => { + const byBuyModal = By.css('span .modal') + const buyModal = await driver.wait(until.elementLocated(byBuyModal)) + const closeModal = await findElement(driver, By.css('.page-container__header-close')) + await closeModal.click() + await driver.wait(until.stalenessOf(buyModal)) + await delay(regularDelayMs) + }) + }) + + describe('Show account information', () => { + it('show account details dropdown menu', async () => { + await driver.findElement(By.css('div.menu-bar__open-in-browser')).click() + const options = await driver.findElements(By.css('div.menu.account-details-dropdown div.menu__item')) + assert.equal(options.length, 3) // HD Wallet type does not have to show the Remove Account option + await delay(regularDelayMs) + }) + }) + + describe('Import seed phrase', () => { + it('logs out of the vault', async () => { + await driver.findElement(By.css('.account-menu__icon')).click() + await delay(regularDelayMs) + + const logoutButton = await findElement(driver, By.css('.account-menu__logout-button')) + assert.equal(await logoutButton.getText(), 'Log out') + await logoutButton.click() + await delay(regularDelayMs) + }) + + it('imports seed phrase', async () => { + const restoreSeedLink = await findElement(driver, By.css('.unlock-page__link--import')) + assert.equal(await restoreSeedLink.getText(), 'Import using account seed phrase') + await restoreSeedLink.click() + await delay(regularDelayMs) + + const seedTextArea = await findElement(driver, By.css('textarea')) + await seedTextArea.sendKeys(testSeedPhrase) + await delay(regularDelayMs) + + const passwordInputs = await driver.findElements(By.css('input')) + await delay(regularDelayMs) + + await passwordInputs[0].sendKeys('correct horse battery staple') + await passwordInputs[1].sendKeys('correct horse battery staple') + await driver.findElement(By.css('.first-time-flow__button')).click() + await delay(regularDelayMs) + }) + + it('switches to localhost', async () => { + const networkDropdown = await findElement(driver, By.css('.network-name')) + await networkDropdown.click() + await delay(regularDelayMs) + + const [localhost] = await findElements(driver, By.xpath(`//span[contains(text(), 'Localhost')]`)) + await localhost.click() + await delay(largeDelayMs * 2) + }) + + it('balance renders', async () => { + const balance = await findElement(driver, By.css('.transaction-view-balance__primary-balance')) + await driver.wait(until.elementTextMatches(balance, /100\s*ETH/)) + await delay(regularDelayMs) + }) + }) + + describe('Send ETH from inside MetaMask', () => { + it('starts to send a transaction', async function () { + const sendButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Send')]`)) + await sendButton.click() + await delay(regularDelayMs) + + const inputAddress = await findElement(driver, By.css('input[placeholder="Recipient Address"]')) + const inputAmount = await findElement(driver, By.css('.unit-input__input')) + await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970') + await inputAmount.sendKeys('1') + + const inputValue = await inputAmount.getAttribute('value') + assert.equal(inputValue, '1') + + // Set the gas limit + const configureGas = await findElement(driver, By.css('.send-v2__gas-fee-display button')) + await configureGas.click() + await delay(regularDelayMs) + + const gasModal = await driver.findElement(By.css('span .modal')) + + const save = await findElement(driver, By.xpath(`//button[contains(text(), 'Save')]`)) + await save.click() + await driver.wait(until.stalenessOf(gasModal)) + await delay(regularDelayMs) + + // Continue to next screen + const nextScreen = await findElement(driver, By.xpath(`//button[contains(text(), 'Next')]`)) + await nextScreen.click() + await delay(regularDelayMs) + }) + + it('confirms the transaction', async function () { + const confirmButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`)) + await confirmButton.click() + await delay(largeDelayMs) + }) + + it('finds the transaction in the transactions list', async function () { + const transactions = await findElements(driver, By.css('.transaction-list-item')) + assert.equal(transactions.length, 1) + + if (process.env.SELENIUM_BROWSER !== 'firefox') { + const txValues = await findElement(driver, By.css('.transaction-list-item__amount--primary')) + await driver.wait(until.elementTextMatches(txValues, /-1\s*ETH/), 10000) + } + }) + }) +}) diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js index 8d1ecac0d..3bfa1eaf2 100644 --- a/test/e2e/beta/metamask-beta-ui.spec.js +++ b/test/e2e/beta/metamask-beta-ui.spec.js @@ -271,16 +271,21 @@ describe('MetaMask', function () { await driver.wait(until.stalenessOf(accountModal)) await delay(regularDelayMs) }) - it('show account details dropdown menu', async () => { + }) + + 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 {width, height} = await driver.manage().window().getSize() - driver.manage().window().setSize(320, 480) - await driver.findElement(By.css('div.menu-bar__open-in-browser')).click() - const options = await driver.findElements(By.css('div.menu.account-details-dropdown div.menu__item')) - assert.equal(options.length, 3) // HD Wallet type does not have to show the Remove Account option + const customRpcButton = await findElement(driver, By.xpath(`//span[contains(text(), 'Custom RPC')]`)) + await customRpcButton.click() await delay(regularDelayMs) - driver.manage().window().setSize(width, height) + 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) }) }) @@ -371,7 +376,7 @@ describe('MetaMask', function () { it('balance renders', async () => { const balance = await findElement(driver, By.css('.balance-display .token-amount')) - await driver.wait(until.elementTextMatches(balance, /100.+ETH/)) + await driver.wait(until.elementTextMatches(balance, /100\s*ETH/)) await delay(regularDelayMs) }) }) @@ -383,7 +388,7 @@ describe('MetaMask', function () { await delay(regularDelayMs) const inputAddress = await findElement(driver, By.css('input[placeholder="Recipient Address"]')) - const inputAmount = await findElement(driver, By.css('.currency-display__input')) + const inputAmount = await findElement(driver, By.css('.unit-input__input')) await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970') await inputAmount.sendKeys('1') @@ -420,30 +425,43 @@ describe('MetaMask', function () { if (process.env.SELENIUM_BROWSER !== 'firefox') { const txValues = await findElement(driver, By.css('.transaction-list-item__amount--primary')) - await driver.wait(until.elementTextMatches(txValues, /-1\sETH/), 10000) + await driver.wait(until.elementTextMatches(txValues, /-1\s*ETH/), 10000) } }) }) 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')]`)) @@ -462,7 +480,7 @@ describe('MetaMask', function () { assert.equal(transactions.length, 2) const txValues = await findElement(driver, By.css('.transaction-list-item__amount--primary')) - await driver.wait(until.elementTextMatches(txValues, /-3\sETH/), 10000) + await driver.wait(until.elementTextMatches(txValues, /-3\s*ETH/), 10000) }) }) @@ -540,7 +558,7 @@ describe('MetaMask', function () { await findElements(driver, By.css('.transaction-list-item')) const [txListValue] = await findElements(driver, By.css('.transaction-list-item__amount--primary')) - await driver.wait(until.elementTextMatches(txListValue, /-4\sETH/), 10000) + await driver.wait(until.elementTextMatches(txListValue, /-4\s*ETH/), 10000) await txListValue.click() await delay(regularDelayMs) @@ -574,7 +592,7 @@ describe('MetaMask', function () { }, 10000) const txValues = await findElements(driver, By.css('.transaction-list-item__amount--primary')) - await driver.wait(until.elementTextMatches(txValues[0], /-4\sETH/), 10000) + await driver.wait(until.elementTextMatches(txValues[0], /-4\s*ETH/), 10000) // const txAccounts = await findElements(driver, By.css('.tx-list-account')) // const firstTxAddress = await txAccounts[0].getText() @@ -606,7 +624,7 @@ describe('MetaMask', function () { }, 10000) const txValues = await findElement(driver, By.css('.transaction-list-item__amount--primary')) - await driver.wait(until.elementTextMatches(txValues, /-0\sETH/), 10000) + await driver.wait(until.elementTextMatches(txValues, /-0\s*ETH/), 10000) await closeAllWindowHandlesExcept(driver, [extension, dapp]) await driver.switchTo().window(extension) @@ -616,9 +634,9 @@ describe('MetaMask', function () { const balance = await findElement(driver, By.css('.transaction-view-balance__primary-balance')) await delay(regularDelayMs) if (process.env.SELENIUM_BROWSER !== 'firefox') { - await driver.wait(until.elementTextMatches(balance, /^92.*ETH.*$/), 10000) + await driver.wait(until.elementTextMatches(balance, /^92.*\s*ETH.*$/), 10000) const tokenAmount = await balance.getText() - assert.ok(/^92.*ETH.*$/.test(tokenAmount)) + assert.ok(/^92.*\s*ETH.*$/.test(tokenAmount)) await delay(regularDelayMs) } }) @@ -662,7 +680,7 @@ describe('MetaMask', function () { }) it('clicks on the Add Token button', async () => { - const addToken = await driver.findElement(By.css('.wallet-view__add-token-button')) + const addToken = await driver.findElement(By.xpath(`//div[contains(text(), 'Add Token')]`)) await addToken.click() await delay(regularDelayMs) }) @@ -702,7 +720,7 @@ describe('MetaMask', function () { await delay(regularDelayMs) const inputAddress = await findElement(driver, By.css('input[placeholder="Recipient Address"]')) - const inputAmount = await findElement(driver, By.css('.currency-display__input')) + const inputAmount = await findElement(driver, By.css('.unit-input__input')) await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970') await inputAmount.sendKeys('50') @@ -764,7 +782,7 @@ describe('MetaMask', function () { // test cancelled on firefox until https://github.com/mozilla/geckodriver/issues/906 is resolved, // or possibly until we use latest version of firefox in the tests if (process.env.SELENIUM_BROWSER !== 'firefox') { - await driver.wait(until.elementTextMatches(txValues[0], /-50\sTST/), 10000) + await driver.wait(until.elementTextMatches(txValues[0], /-50\s*TST/), 10000) } driver.wait(async () => { @@ -798,7 +816,7 @@ describe('MetaMask', function () { await findElements(driver, By.css('.transaction-list__pending-transactions')) const [txListValue] = await findElements(driver, By.css('.transaction-list-item__amount--primary')) - await driver.wait(until.elementTextMatches(txListValue, /-7\sTST/), 10000) + await driver.wait(until.elementTextMatches(txListValue, /-7\s*TST/), 10000) await txListValue.click() await delay(regularDelayMs) @@ -834,8 +852,8 @@ describe('MetaMask', function () { await save.click() await driver.wait(until.stalenessOf(gasModal)) - const gasFeeInputs = await findElements(driver, By.css('.confirm-detail-row__eth')) - assert.equal(await gasFeeInputs[0].getText(), '♦ 0.0006') + const gasFeeInputs = await findElements(driver, By.css('.confirm-detail-row__primary')) + assert.equal(await gasFeeInputs[0].getText(), '0.0006') }) it('submits the transaction', async function () { @@ -851,7 +869,7 @@ describe('MetaMask', function () { }, 10000) const txValues = await findElements(driver, By.css('.transaction-list-item__amount--primary')) - await driver.wait(until.elementTextMatches(txValues[0], /-7\sTST/)) + await driver.wait(until.elementTextMatches(txValues[0], /-7\s*TST/)) const txStatuses = await findElements(driver, By.css('.transaction-list-item__action')) await driver.wait(until.elementTextMatches(txStatuses[0], /Sent\sToken/)) @@ -897,7 +915,7 @@ describe('MetaMask', function () { const [txListItem] = await findElements(driver, By.css('.transaction-list-item')) const [txListValue] = await findElements(driver, By.css('.transaction-list-item__amount--primary')) - await driver.wait(until.elementTextMatches(txListValue, /-7\sTST/)) + await driver.wait(until.elementTextMatches(txListValue, /-7\s*TST/)) await txListItem.click() await delay(regularDelayMs) }) @@ -957,8 +975,8 @@ describe('MetaMask', function () { await save.click() await driver.wait(until.stalenessOf(gasModal)) - const gasFeeInputs = await findElements(driver, By.css('.confirm-detail-row__eth')) - assert.equal(await gasFeeInputs[0].getText(), '♦ 0.0006') + const gasFeeInputs = await findElements(driver, By.css('.confirm-detail-row__primary')) + assert.equal(await gasFeeInputs[0].getText(), '0.0006') }) it('submits the transaction', async function () { @@ -974,7 +992,7 @@ describe('MetaMask', function () { }, 10000) const txValues = await findElements(driver, By.css('.transaction-list-item__amount--primary')) - await driver.wait(until.elementTextMatches(txValues[0], /-7\sTST/)) + await driver.wait(until.elementTextMatches(txValues[0], /-7\s*TST/)) const txStatuses = await findElements(driver, By.css('.transaction-list-item__action')) await driver.wait(until.elementTextMatches(txStatuses[0], /Approve/)) }) @@ -1002,7 +1020,7 @@ describe('MetaMask', function () { describe('Add existing token using search', () => { it('clicks on the Add Token button', async () => { - const addToken = await findElement(driver, By.xpath(`//button[contains(text(), 'Add Token')]`)) + const addToken = await findElement(driver, By.xpath(`//div[contains(text(), 'Add Token')]`)) await addToken.click() await delay(regularDelayMs) }) @@ -1027,7 +1045,7 @@ describe('MetaMask', function () { it('renders the balance for the chosen token', async () => { const balance = await findElement(driver, By.css('.transaction-view-balance__token-balance')) - await driver.wait(until.elementTextMatches(balance, /0\sBAT/)) + await driver.wait(until.elementTextMatches(balance, /0\s*BAT/)) await delay(regularDelayMs) }) }) diff --git a/test/e2e/beta/run-all.sh b/test/e2e/beta/run-all.sh index c51f19fdf..f2705da4c 100755 --- a/test/e2e/beta/run-all.sh +++ b/test/e2e/beta/run-all.sh @@ -7,4 +7,5 @@ set -o pipefail export PATH="$PATH:./node_modules/.bin" shell-parallel -s 'npm run ganache:start -- -b 2' -x 'sleep 5 && static-server test/e2e/beta/contract-test --port 8080' -x 'sleep 5 && mocha test/e2e/beta/metamask-beta-ui.spec' +shell-parallel -s 'npm run ganache:start -- -b 2' -x 'sleep 5 && static-server test/e2e/beta/contract-test --port 8080' -x 'sleep 5 && mocha test/e2e/beta/metamask-beta-responsive-ui.spec' shell-parallel -s 'npm run ganache:start -- -d -b 2' -x 'sleep 5 && mocha test/e2e/beta/from-import-beta-ui.spec' diff --git a/test/e2e/beta/run-drizzle.sh b/test/e2e/beta/run-drizzle.sh index 7bfffd7e6..bfb7e6fdb 100755 --- a/test/e2e/beta/run-drizzle.sh +++ b/test/e2e/beta/run-drizzle.sh @@ -11,7 +11,7 @@ sleep 5 cd test/e2e/beta/ rm -rf drizzle-test mkdir drizzle-test && cd drizzle-test -npm install truffle +sudo npm install -g truffle truffle unbox drizzle echo "Deploying contracts for Drizzle test..." truffle compile && truffle migrate diff --git a/test/e2e/func.js b/test/e2e/func.js index 13dfb82f9..5301d78ae 100644 --- a/test/e2e/func.js +++ b/test/e2e/func.js @@ -56,23 +56,31 @@ async function setupBrowserAndExtension ({ browser, extPath }) { return { driver, extensionId, extensionUri } } -function buildChromeWebDriver (extPath) { +function buildChromeWebDriver (extPath, opts = {}) { const tmpProfile = fs.mkdtempSync(path.join(os.tmpdir(), 'mm-chrome-profile')) + const args = [ + `load-extension=${extPath}`, + `user-data-dir=${tmpProfile}`, + ] + if (opts.responsive) { + args.push('--auto-open-devtools-for-tabs') + } return new webdriver.Builder() .withCapabilities({ chromeOptions: { - args: [ - `load-extension=${extPath}`, - `user-data-dir=${tmpProfile}`, - ], + args, binary: process.env.SELENIUM_CHROME_BINARY, }, }) .build() } -function buildFirefoxWebdriver () { - return new webdriver.Builder().build() +function buildFirefoxWebdriver (opts = {}) { + const driver = new webdriver.Builder().build() + if (opts.responsive) { + driver.manage().window().setSize(320, 600) + } + return driver } async function getExtensionIdChrome (driver) { diff --git a/test/integration/lib/add-token.js b/test/integration/lib/add-token.js deleted file mode 100644 index bb9d0d10f..000000000 --- a/test/integration/lib/add-token.js +++ /dev/null @@ -1,140 +0,0 @@ -const reactTriggerChange = require('react-trigger-change') -const { - timeout, - queryAsync, - findAsync, -} = require('../../lib/util') - -QUnit.module('Add token flow') - -QUnit.test('successful add token flow', (assert) => { - const done = assert.async() - runAddTokenFlowTest(assert) - .then(done) - .catch(err => { - assert.notOk(err, `Error was thrown: ${err.stack}`) - done() - }) -}) - -async function runAddTokenFlowTest (assert, done) { - const selectState = await queryAsync($, 'select') - selectState.val('add token') - reactTriggerChange(selectState[0]) - - // Used to set values on TextField input component - const nativeInputValueSetter = Object.getOwnPropertyDescriptor( - window.HTMLInputElement.prototype, 'value' - ).set - - // Check that no tokens have been added - assert.ok($('.token-list-item').length === 0, 'no tokens added') - - // Go to Add Token screen - let addTokenButton = await queryAsync($, 'button.btn-primary.wallet-view__add-token-button') - assert.ok(addTokenButton[0], 'add token button present') - addTokenButton[0].click() - - // Verify Add Token screen - let addTokenWrapper = await queryAsync($, '.page-container') - assert.ok(addTokenWrapper[0], 'add token wrapper renders') - - let addTokenTitle = await queryAsync($, '.page-container__title') - assert.equal(addTokenTitle[0].textContent, 'Add Tokens', 'add token title is correct') - - // Cancel Add Token - const cancelAddTokenButton = await queryAsync($, 'button.btn-default.btn--large.page-container__footer-button') - assert.ok(cancelAddTokenButton[0], 'cancel add token button present') - cancelAddTokenButton.click() - - assert.ok($('.wallet-view')[0], 'cancelled and returned to account detail wallet view') - - // Return to Add Token Screen - addTokenButton = await queryAsync($, 'button.btn-primary.wallet-view__add-token-button') - assert.ok(addTokenButton[0], 'add token button present') - addTokenButton[0].click() - - // Verify Add Token Screen - addTokenWrapper = await queryAsync($, '.page-container') - addTokenTitle = await queryAsync($, '.page-container__title') - assert.ok(addTokenWrapper[0], 'add token wrapper renders') - assert.equal(addTokenTitle[0].textContent, 'Add Tokens', 'add token title is correct') - - // Search for token - const searchInput = (await findAsync(addTokenWrapper, '#search-tokens'))[0] - searchInput.focus() - await timeout(1000) - nativeInputValueSetter.call(searchInput, 'a') - searchInput.dispatchEvent(new Event('input', { bubbles: true})) - - // Click token to add - const tokenWrapper = await queryAsync($, 'div.token-list__token') - assert.ok(tokenWrapper[0], 'token found') - const tokenImageProp = tokenWrapper.find('.token-list__token-icon').css('background-image') - const tokenImageUrl = tokenImageProp.slice(5, -2) - tokenWrapper[0].click() - - // Click Next button - const nextButton = await queryAsync($, 'button.btn-primary.btn--large') - assert.equal(nextButton[0].textContent, 'Next', 'next button rendered') - nextButton[0].click() - - // Confirm Add token - const confirmAddToken = await queryAsync($, '.confirm-add-token') - assert.ok(confirmAddToken[0], 'confirm add token rendered') - assert.ok($('button.btn-primary.btn--large')[0], 'confirm add token button found') - $('button.btn-primary.btn--large')[0].click() - - // Verify added token image - let heroBalance = await queryAsync($, '.transaction-view-balance__balance-container') - assert.ok(heroBalance, 'rendered hero balance') - assert.ok(tokenImageUrl.indexOf(heroBalance.find('img').attr('src')) > -1, 'token added') - - // Return to Add Token Screen - addTokenButton = await queryAsync($, 'button.btn-primary.wallet-view__add-token-button') - assert.ok(addTokenButton[0], 'add token button present') - addTokenButton[0].click() - - addTokenWrapper = await queryAsync($, '.page-container') - const addTokenTabs = await queryAsync($, '.page-container__tab') - assert.equal(addTokenTabs.length, 2, 'expected number of tabs') - assert.equal(addTokenTabs[1].textContent, 'Custom Token', 'Custom Token tab present') - assert.ok(addTokenTabs[1], 'add custom token tab present') - addTokenTabs[1].click() - await timeout(1000) - - // Input token contract address - const customInput = (await findAsync(addTokenWrapper, '#custom-address'))[0] - customInput.focus() - await timeout(1000) - nativeInputValueSetter.call(customInput, '0x177af043D3A1Aed7cc5f2397C70248Fc6cDC056c') - customInput.dispatchEvent(new Event('input', { bubbles: true})) - - - // Click Next button - // nextButton = await queryAsync($, 'button.btn-primary--lg') - // assert.equal(nextButton[0].textContent, 'Next', 'next button rendered') - // nextButton[0].click() - - // // Verify symbol length error since contract address won't return symbol - const errorMessage = await queryAsync($, '#custom-symbol-helper-text') - assert.ok(errorMessage[0], 'error rendered') - - $('button.btn-default.btn--large')[0].click() - - // await timeout(100000) - - // Confirm Add token - // assert.equal( - // $('.page-container__subtitle')[0].textContent, - // 'Would you like to add these tokens?', - // 'confirm add token rendered' - // ) - // assert.ok($('button.btn-primary--lg')[0], 'confirm add token button found') - // $('button.btn-primary--lg')[0].click() - - // Verify added token image - heroBalance = await queryAsync($, '.transaction-view-balance__balance-container') - assert.ok(heroBalance, 'rendered hero balance') - assert.ok(heroBalance.find('.identicon')[0], 'token added') -} diff --git a/test/integration/lib/currency-localization.js b/test/integration/lib/currency-localization.js index 8d5acf5d0..f6b751ba2 100644 --- a/test/integration/lib/currency-localization.js +++ b/test/integration/lib/currency-localization.js @@ -25,5 +25,5 @@ async function runCurrencyLocalizationTest (assert, done) { const txView = await queryAsync($, '.transaction-view') const heroBalance = await findAsync($(txView), '.transaction-view-balance__balance') const fiatAmount = await findAsync($(heroBalance), '.transaction-view-balance__secondary-balance') - assert.equal(fiatAmount[0].textContent, '₱102,707.97 PHP') + assert.equal(fiatAmount[0].textContent, '₱102,707.97PHP') } 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/integration/lib/send-new-ui.js b/test/integration/lib/send-new-ui.js index ac1cc2e14..271dd91cf 100644 --- a/test/integration/lib/send-new-ui.js +++ b/test/integration/lib/send-new-ui.js @@ -40,7 +40,7 @@ async function customizeGas (assert, price, limit, ethFee, usdFee) { const sendGasField = await queryAsync($, '.send-v2__gas-fee-display') assert.equal( - (await findAsync(sendGasField, '.currency-display__input-wrapper > input')).val(), + (await findAsync(sendGasField, '.currency-display-component'))[0].textContent, ethFee, 'send gas field should show customized gas total' ) @@ -97,9 +97,9 @@ async function runSendFlowTest (assert, done) { assert.equal(sendToAccountAddress, '0x2f8D4a878cFA04A6E60D46362f5644DeAb66572D', 'send to dropdown selects the correct address') const sendAmountField = await queryAsync($, '.send-v2__form-row:eq(2)') - sendAmountField.find('.currency-display')[0].click() + sendAmountField.find('.unit-input')[0].click() - const sendAmountFieldInput = await findAsync(sendAmountField, '.currency-display__input') + const sendAmountFieldInput = await findAsync(sendAmountField, '.unit-input__input') sendAmountFieldInput.val('5.1') reactTriggerChange(sendAmountField.find('input')[0]) @@ -112,9 +112,9 @@ async function runSendFlowTest (assert, done) { errorMessage = $('.send-v2__error') assert.equal(errorMessage.length, 0, 'send should stop rendering amount error message after amount is corrected') - await customizeGas(assert, 0, 21000, '0', '$0.00 USD') - await customizeGas(assert, 1, 21000, '0.000021', '$0.03 USD') - await customizeGas(assert, 500, 60000, '0.03', '$36.03 USD') + await customizeGas(assert, 0, 21000, '0ETH', '$0.00USD') + await customizeGas(assert, 1, 21000, '0.000021ETH', '$0.03USD') + await customizeGas(assert, 500, 60000, '0.03ETH', '$36.03USD') const sendButton = await queryAsync($, 'button.btn-primary.btn--large.page-container__footer-button') assert.equal(sendButton[0].textContent, 'Next', 'next button rendered') @@ -130,11 +130,11 @@ async function runSendFlowTest (assert, done) { const confirmToName = (await queryAsync($, '.sender-to-recipient__name')).last() assert.equal(confirmToName[0].textContent, 'Send Account 3', 'confirm screen should show correct to name') - const confirmScreenRowFiats = await queryAsync($, '.confirm-detail-row__fiat') + const confirmScreenRowFiats = await queryAsync($, '.confirm-detail-row__secondary') const confirmScreenGas = confirmScreenRowFiats[0] assert.equal(confirmScreenGas.textContent, '$3.60', 'confirm screen should show correct gas') const confirmScreenTotal = confirmScreenRowFiats[1] - assert.equal(confirmScreenTotal.textContent, '$2,405.36', 'confirm screen should show correct total') + assert.equal(confirmScreenTotal.textContent, '$2,405.37', 'confirm screen should show correct total') const confirmScreenBackButton = await queryAsync($, '.confirm-page-container-header__back-button') confirmScreenBackButton[0].click() @@ -150,9 +150,9 @@ async function runSendFlowTest (assert, done) { sendToFieldInputInEdit.val('0xd85a4b6a394794842887b8284293d69163007bbb') const sendAmountFieldInEdit = await queryAsync($, '.send-v2__form-row:eq(2)') - sendAmountFieldInEdit.find('.currency-display')[0].click() + sendAmountFieldInEdit.find('.unit-input')[0].click() - const sendAmountFieldInputInEdit = sendAmountFieldInEdit.find('.currency-display__input') + const sendAmountFieldInputInEdit = sendAmountFieldInEdit.find('.unit-input__input') sendAmountFieldInputInEdit.val('1.0') reactTriggerChange(sendAmountFieldInputInEdit[0]) diff --git a/test/unit/app/controllers/network-contoller-test.js b/test/unit/app/controllers/network-contoller-test.js index 822311931..7959e6cc1 100644 --- a/test/unit/app/controllers/network-contoller-test.js +++ b/test/unit/app/controllers/network-contoller-test.js @@ -47,7 +47,7 @@ describe('# Network Controller', function () { describe('#setNetworkState', function () { it('should update the network', function () { - networkController.setNetworkState(1) + networkController.setNetworkState(1, 'rpc') const networkState = networkController.getNetworkState() assert.equal(networkState, 1, 'network is 1') }) diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js index b5ccf3fb5..473f22f8b 100644 --- a/test/unit/app/controllers/preferences-controller-test.js +++ b/test/unit/app/controllers/preferences-controller-test.js @@ -375,6 +375,11 @@ describe('preferences controller', function () { await preferencesController.requestWatchAsset(req, res, asy.next, asy.end) sandbox.assert.called(stubEnd) sandbox.assert.notCalled(stubNext) + req.method = 'wallet_watchAsset' + req.params.type = 'someasset' + await preferencesController.requestWatchAsset(req, res, asy.next, asy.end) + sandbox.assert.calledTwice(stubEnd) + sandbox.assert.notCalled(stubNext) }) it('should through error if method is supported but asset type is not', async function () { req.method = 'metamask_watchAsset' @@ -413,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() @@ -433,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) } @@ -448,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 () { @@ -479,5 +510,24 @@ describe('preferences controller', function () { assert.equal(preferencesController.store.getState().seedWords, 'foo bar baz') }) }) + + describe('on updateFrequentRpcList', function () { + it('should add custom RPC url to state', function () { + preferencesController.addToFrequentRpcList('rpc_url', 1) + preferencesController.addToFrequentRpcList('http://localhost:8545', 1) + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }] ) + preferencesController.addToFrequentRpcList('rpc_url', 1) + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }] ) + }) + + it('should remove custom RPC url from state', function () { + preferencesController.addToFrequentRpcList('rpc_url', 1) + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: 1, ticker: 'ETH', nickname: '' }] ) + preferencesController.removeFromFrequentRpcList('other_rpc_url') + preferencesController.removeFromFrequentRpcList('http://localhost:8545') + preferencesController.removeFromFrequentRpcList('rpc_url') + assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, []) + }) + }) }) diff --git a/test/unit/components/balance-component-test.js b/test/unit/components/balance-component-test.js deleted file mode 100644 index aa9763b72..000000000 --- a/test/unit/components/balance-component-test.js +++ /dev/null @@ -1,44 +0,0 @@ -const assert = require('assert') -const h = require('react-hyperscript') -const { createMockStore } = require('redux-test-utils') -const { shallowWithStore } = require('../../lib/render-helpers') -const BalanceComponent = require('../../../ui/app/components/balance-component') -const mockState = { - metamask: { - accounts: { abc: {} }, - network: 1, - selectedAddress: 'abc', - }, -} - -describe('BalanceComponent', function () { - let balanceComponent - let store - let component - beforeEach(function () { - store = createMockStore(mockState) - component = shallowWithStore(h(BalanceComponent), store) - balanceComponent = component.dive() - }) - - it('shows token balance and convert to fiat value based on conversion rate', function () { - const formattedBalance = '1.23 ETH' - - const tokenBalance = balanceComponent.instance().getTokenBalance(formattedBalance, false) - const fiatDisplayNumber = balanceComponent.instance().getFiatDisplayNumber(formattedBalance, 2) - - assert.equal('1.23 ETH', tokenBalance) - assert.equal(2.46, fiatDisplayNumber) - }) - - it('shows only the token balance when conversion rate is not available', function () { - const formattedBalance = '1.23 ETH' - - const tokenBalance = balanceComponent.instance().getTokenBalance(formattedBalance, false) - const fiatDisplayNumber = balanceComponent.instance().getFiatDisplayNumber(formattedBalance, 0) - - assert.equal('1.23 ETH', tokenBalance) - assert.equal('N/A', fiatDisplayNumber) - }) - -}) diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index 748a58b32..df7d2ee8f 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -1133,7 +1133,7 @@ describe('Actions', () => { { type: 'DISPLAY_WARNING', value: 'Had a problem changing networks!' }, ] - setRpcTargetSpy.callsFake((newRpc, callback) => { + setRpcTargetSpy.callsFake((newRpc, chainId, ticker, nickname, callback) => { callback(new Error('error')) }) diff --git a/test/unit/ui/app/components/identicon.spec.js b/test/unit/ui/app/components/identicon.spec.js deleted file mode 100644 index a2f8d8246..000000000 --- a/test/unit/ui/app/components/identicon.spec.js +++ /dev/null @@ -1,36 +0,0 @@ -import React from 'react' -import assert from 'assert' -import thunk from 'redux-thunk' -import configureMockStore from 'redux-mock-store' -import { mount } from 'enzyme' - -import IdenticonComponent from '../../../../../ui/app/components/identicon' - -describe('Identicon Component', () => { - - const state = { - metamask: { - useBlockie: false, - }, - } - - const middlewares = [thunk] - const mockStore = configureMockStore(middlewares) - const store = mockStore(state) - - it('renders default eth_logo identicon with no props', () => { - const wrapper = mount(<IdenticonComponent store={store}/>) - assert.equal(wrapper.find('img.balance-icon').prop('src'), './images/eth_logo.svg') - }) - - it('renders custom image and add className props', () => { - const wrapper = mount(<IdenticonComponent store={store} className={'test-image'} image={'test-image'} />) - assert.equal(wrapper.find('img.test-image').prop('className'), 'test-image identicon') - assert.equal(wrapper.find('img.test-image').prop('src'), 'test-image') - }) - - it('renders div with address prop', () => { - const wrapper = mount(<IdenticonComponent store={store} className={'test-address'} address={'0xTest'} />) - assert.equal(wrapper.find('div.test-address').prop('className'), 'test-address identicon') - }) -}) 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, {}) + }) +}) |