From 33182efb1384dc05c8ecdb8994d12dd30abcbc7e Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Thu, 15 Feb 2018 08:34:31 -0800 Subject: Offline testing --- test/stub/blacklist.json | 1374 ++++++++++++++++++++++++++++++++ test/stub/first-time-state.js | 14 + test/unit/blacklist-controller-test.js | 2 +- test/unit/metamask-controller-test.js | 178 ++--- test/unit/network-contoller-test.js | 4 + 5 files changed, 1469 insertions(+), 103 deletions(-) create mode 100644 test/stub/blacklist.json create mode 100644 test/stub/first-time-state.js (limited to 'test') diff --git a/test/stub/blacklist.json b/test/stub/blacklist.json new file mode 100644 index 000000000..6a3230b2f --- /dev/null +++ b/test/stub/blacklist.json @@ -0,0 +1,1374 @@ +{ + "version": 2, + "tolerance": 2, + "fuzzylist": [ + "metamask.io", + "myetherwallet.com", + "cryptokitties.co", + "mycrypto.com" + ], + "whitelist": [ + "crypto.pro", + "ocrypto.org", + "wecrypto.net", + "iccrypto.io", + "crypto.kred", + "ohmycrypto.io", + "spcrypto.net", + "melcrypto.com", + "zzcrypto.org", + "zzcrypto.net", + "crypto.bg", + "mycrypto24.online", + "acrypto.io", + "mycrypto.ca", + "scrypto.io", + "mycrypto.dk", + "mvzcrypto.com", + "ambcrypto.com", + "crypto.bi", + "crypto.jobs", + "crypto.help", + "my.crypt.observer", + "crypt.observer", + "ucrypto.com", + "cryptojobslist.com", + "crypto.review", + "crypto.me", + "b3crypto.com", + "mycrypto.ninja", + "jkcrypto.com", + "crypto.cr", + "mycrypto.live", + "yocrypto.io", + "crypto.ba", + "zacrypto.info", + "mycrypto.com", + "remix.ethereum.org", + "metahash.io", + "metahash.net", + "metahash.org", + "cryptotitties.com", + "cryptocities.net", + "cryptoshitties.co", + "cryptotitties.fun", + "cryptokitties.forsale", + "cryptokitties.care", + "metamate.cc", + "metamesh.tech", + "ico.nexus.social", + "metamesh.org", + "metatask.io", + "metmask.com", + "metarasa.com", + "metapack.com", + "metacase.com", + "metafas.nl", + "metamako.com", + "metamast.com", + "metamax.ru", + "metadesk.io", + "metadisk.com", + "metallsk.ru", + "metamag.fr", + "metamaks.ru", + "metamap.ru", + "metamaps.cc", + "metamats.com", + "metamax.by", + "metamax.com", + "metamax.io", + "metamuse.net", + "metarank.com", + "metaxas.com", + "megamas2.ru", + "metamask.io", + "myetherwallet.com", + "myethlerwallet.com", + "ethereum.org", + "myetheroll.com", + "myetherapi.com", + "ledgerwallet.com", + "databrokerdao.com", + "etherscan.io", + "etherid.org", + "ether.cards", + "etheroll.com", + "ethnews.com", + "ethex.market", + "ethereumdev.io", + "ethereumdev.kr", + "dether.io", + "ethermine.org", + "slaask.com", + "etherbtc.io", + "ethereal.capital", + "etherisc.com", + "m.famalk.net", + "etherecho.com", + "ethereum.os.tc", + "theethereum.wiki", + "metajack.im", + "etherhub.io", + "ethereum.network", + "ethereum.link", + "ethereum.com", + "prethereum.org", + "ethereumj.io", + "etheraus.com", + "ethereum.dev", + "1ethereum.ru", + "ethereum.nz", + "nethereum.com", + "metabank.com", + "metamas.com", + "aventus.io", + "metabase.com", + "etherdelta.com", + "metabase.one", + "cryptokitties.co", + "remme.io", + "jibrel.network" + ], + "blacklist": [ + "xn--myethrwalle-jb9e19a.com", + "xn--myetheralle-7b9ezl.com", + "iconfoundation.co", + "fundrequest.info", + "xn--myetherwale-os8e7x.com", + "remme-ico.eu", + "gonetwork.live", + "token.gonetwork.pro", + "gonetwork.pro", + "gonetwork.eu", + "nucleus-vision.cc", + "jibreltoken.in", + "dock.so", + "dock.promo", + "xn--mycrypt-r0a.com", + "xn--mycrypt-g1a.com", + "xn--mycrpto-y2a.com", + "ethexploit.org", + "remme.in", + "remme.ws", + "remme.com.ng", + "nyeitthervvallet.com", + "xn--myeerhwailet-ooc.com", + "myeterhwaliot.com", + "remme.live", + "xn--yethewalle-to2exkhi.com", + "myetherwallet.custom-token.com", + "custom-token.com", + "sale-earn.com", + "bankera.live", + "originprotocol.io", + "trx.foundation", + "tokensale.adhive.net", + "adhive.net", + "decentral.market", + "cryptoexploite.com", + "blockclain.net", + "xn--blckchin-5za9o.info", + "xn--blkhain-m0a4pb.info", + "xn--blocchal-gmb8m.info", + "xn--blocchaln-orb.info", + "xn--blocchan-gmb7c.info", + "xn--blockaden-lsen-5pb.com", + "xn--blockchai-3vb.info", + "xn--blockchai-jvb.info", + "xn--blockchal-3vb.info", + "xn--blockcham-ipb.info", + "xn--blockchan-2pb.com", + "xn--blockchan-75a.com", + "xn--blockchan-7sb.info", + "xn--blockchan-d5a.net", + "xn--blockchan-dob.info", + "xn--blockchan-ipb.com", + "xn--blockchan-ipb.info", + "xn--blockchan-nk7d.com", + "xn--blockchan-xub.info", + "xn--blockchann-4ub.com", + "xn--blockchi-n7a50e.info", + "xn--blockchi-o8a54d.info", + "xn--blockchi-p99co8a.com", + "xn--blockchim-hdb.info", + "xn--blockchin-1xb.info", + "xn--blockchin-61a.info", + "xn--blockchin-61a.net", + "xn--blockchin-6ib.info", + "xn--blockchin-ccb.info", + "xn--blockchin-h4a.com", + "xn--blockchin-h4a.info", + "xn--blockchin-hdb.info", + "xn--blockchin-hhb.info", + "xn--blockchin-mib.net", + "xn--blockchin-wcb.com", + "xn--blockchn-fza4j.com", + "xn--blockchn-fza4j.info", + "xn--blockchn-n7a43b.info", + "xn--blockchn-p0a.info", + "xn--blockchn-tx0d4p.com", + "xn--blockclai-3vb.info", + "xn--blockclin-hdb.com", + "xn--blockclin-hdb.info", + "xn--blockclin-hdb.org", + "xn--blockflte-kirchrode-w6b.de", + "xn--blockfltenquartett-windspiel-81c.de", + "xn--blockhai-obb78c.info", + "xn--blockhain-4eb.com", + "xn--blockhain-pfb.com", + "xn--blockhain-pfb.info", + "xn--blockhain-zdb.info", + "xn--blockhan-obb65a.info", + "xn--blockhas-d6a.com", + "xn--blockwallt-j7a.com", + "xn--blokchai-fqb.info", + "xn--blokchain-nfb.info", + "xn--blokhain-28ab.info", + "xn--bockclnain-eyb.info", + "xn--mymoeo-zt7bzf.com", + "xn--mymoer-nqc1368c.com", + "xn--mymoero-c13c.com", + "xn--mymoero-s13c.com", + "xn--mymoneo-f63c.com", + "xn--mymoneo-v63c.com", + "xn--mymoneo-y53c.com", + "xn--mymoner-j0a.com", + "xn--mymoner-j5b.com", + "xn--mymoner-r0a.com", + "xn--mymoner-z0a.com", + "xn--mymoner-z2c.com", + "xn--mymonro-fya.com", + "xn--mymonro-x8a.com", + "xn--myetheallet-l58emu.com", + "xn--myetheraet-9k2ea77h.com", + "xn--myetheralet-ms8e21b.com", + "xn--myetheralle-7b9exm.com", + "xn--myetherallet-5s5f.com", + "xn--myetherallet-fs5f.com", + "xn--myetherewalle-1t1g.com", + "xn--myetherllet-pl9e6k.com", + "xn--myethervvalle-8vc.com", + "xn--myetherwaet-61ea.com", + "xn--myetherwaet-8eda.com", + "xn--myetherwaet-ns8ea.com", + "xn--myetherwale-ns8e8x.com", + "xn--myetherwalet-0fb.com", + "xn--myetherwalet-0z4f.com", + "xn--myetherwalet-814f.com", + "xn--myetherwalet-d9b.com", + "xn--myetherwalet-h14f.com", + "xn--myetherwalle-9me.com", + "xn--myetherwalle-ek5f.com", + "xn--myetherwalle-fqc.com", + "xn--myetherwalle-opc.com", + "xn--myetherwalle-q05f.com", + "xn--myetherwllet-wob.com", + "xn--myetherwllt-r7a0i.com", + "xn--myethewaliet-9d5f.com", + "xn--myethewalle-3ic0947g.com", + "xn--myethewallet-0e5f.com", + "xn--myethewallet-1kc.com", + "xn--myethewallet-bkc.com", + "xn--myethewallet-vof.com", + "xn--myethewalliet-nm1g.com", + "xn--myethewallt-kbb3019g.com", + "xn--myethewallt-w48ew7b.com", + "xn--myethrwalet-6qb6408g.com", + "xn--myethrwalet-ms8e83d.com", + "xn--myethrwallet-1db.com", + "xn--myethrwallt-29af.com", + "xn--myethrwallt-29as.com", + "xn--myethrwllet-q7a31e.com", + "xn--myethrwllet-r8a3c.com", + "fintrux.eu", + "refereum-ico.eu", + "arcblock-ico.org", + "xn--fuson-1sa.org", + "refereum-token.com", + "fintrux.co", + "ico-ton.org", + "xn--mytherwallt-cbbv.com", + "xmoneta.co", + "data-wallet.co", + "tokensale.data-wallet.co", + "xn--myeerhwallot-ooc.com", + "xn--myeterwalet-cm8epi.com", + "xn--myeterwalle-cm8ev6a.com", + "rnyetherumwallet.com", + "republic-protocol.net", + "nyeihitervvallatt.com", + "arcblock.eu", + "republicprotocol.eu", + "tokensale-fusion.com", + "myetherwalletjoin.com", + "medicalchian.com", + "myeahteirwaliet.com", + "myenhtersvvailct.com", + "trinity-token.com", + "xn--eo-yzs.com", + "zilliqa.in", + "sparc.pro", + "myetherwallet.import-tokens.com", + "token-gram.org", + "xn--shapshift-e4a.com", + "xn--shapshift-y4a.com", + "xn--shpeshift-c2a.com", + "xn--shpeshift-r1a.com", + "xn--shapshift-o4a.com", + "xn--shpeshift-w2a.com", + "xn--shapeshft-w5a.com", + "tokensale-fusion.org", + "fusion-ico.com", + "beetolen.com", + "tokencrowdsale.online", + "fusion.tokencrowdsale.online", + "beetokem.com", + "block.chaiins.in", + "origintrail.in", + "bit-z.ru", + "xn--myetherallet-nu5f.com", + "xn--mytherwalet-3qb08c.com", + "xn--myeterwllet-cm8et1d.com", + "xn--mytherwllet-q7a01e.com", + "xn--biance-xt7b.com", + "xn--bnance-wic.com", + "xn--biance-jeb.com", + "xn--bttrx-9za8334c.com", + "wwwkodakcoin.com", + "myetherwallet.uk.com", + "kodakone.cc", + "nyeihitervvallet.com", + "xn--myeterwalet-cm8eoi.com", + "nucleus.foundation", + "beetoken-ico.com", + "data-token.com", + "tron-labs.com", + "ocoin.tech", + "aionfoundation.com", + "ico-telegram.org", + "nyeihitervvallat.com", + "telegramcoin.us", + "daddi.cloud", + "daditoken.com", + "blockarray.org", + "dadi-cloud.net", + "wanchainfunding.org", + "ico-telegram.io", + "iconfoundation.site", + "iost.co", + "beetoken-ico.eu", + "cindicator.network", + "wanchainetwork.org", + "wamchain.org", + "wanchainltd.org", + "wanchainalliance.org", + "nucleus-vision.net", + "ledgerwallet.by", + "nucleuss.vision", + "myenhterswailct.com", + "cobin-hood.com", + "wanchainfoundation.org", + "xn--polniex-ex4c.com", + "xn--polniex-s1a.com", + "xn--polonex-ieb.com", + "xn--polonex-sza.com", + "xn--polonex-zw4c.com", + "xn--polonix-ws4c.com", + "xn--polonix-y8a.com", + "xn--pooniex-ojb.com", + "gramico.info", + "dimnsions.network", + "www-gemini.com", + "login-kucoin.net", + "venchain.foundation", + "grampreico.com", + "tgram.cc", + "ton-gramico.com", + "wwwpaywithink.com", + "coniomi.com", + "paywithnk.com", + "paywithlnk.com", + "iluminatto.com.br", + "pundix.eu", + "xn--bttrx-esay.com", + "xn--bttrex-w8a.com", + "xn--bnance-bwa.com", + "xn--shpeshift-11a.com", + "xn--shapeshif-ts6d.com", + "xn--shapshift-yf7d.com", + "wwwbluzelle.com", + "bluzelie.com", + "nucleus-vision.org", + "omisegonetwork.site", + "etlherzero.com", + "etlherdelta.com", + "xn--condesk-0ya.com", + "xn--condesk-sfb.com", + "xn--coindsk-vs4c.com", + "iexecplatform.com", + "tongramico.com", + "nucleus-vision.eu", + "intchain.network", + "wanchain.cloud", + "bluzelle-ico.com", + "ethzero-wallet.com", + "xn--metherwalle-jb9et7d.com", + "xn--coinesk-jo3c.com", + "venchainfoundation.com", + "myenhtersvvailot.com", + "ether-zero.net", + "ins.foundation", + "nastoken.org", + "telcointoken.com", + "ether0.org", + "eterzero.org", + "bluzelle-ico.eu", + "bleuzelle.com", + "appcoinstoken.org", + "xn--quanstamp-8s6d.com", + "myehntersvvailct.com", + "myeherwalllet.com", + "ico-bluzelle.com", + "bluzelle.im", + "bluzelle.one", + "bluzele.sale", + "bluzele.co", + "sether.ws", + "xn--myetherwalet-6gf.com", + "xn--rnyethewaliet-om1g.com", + "rnyethervailet.com", + "mvetherwaliet.com", + "rnyetherwailet.com", + "myethervaliet.com", + "rnyethervaliet.com", + "mvetherwalilet.com", + "xn--myethewalie-3ic0947g.com", + "xn--mthrwallet-z6ac3y.com", + "xn--myeherwalie-vici.com", + "xn--myethervvalie-8vc.com", + "xn--mythrwallt-06acf.com", + "xn--mtherwallet-y9a6y.com", + "myetherwallet.applytoken.tk", + "ethereum-zero.com", + "quanstamptoken.tk", + "bluzelle.network", + "ether-wallet.org", + "tron-wallet.info", + "appcoinsproject.com", + "vechain.foundation", + "tronlab.site", + "tronlabs.network", + "bluzelle.cc", + "ethblender.com", + "ethpaperwallet.net", + "waltontoken.org", + "icoselfkey.org", + "etherzeroclaim.com", + "etherzero.promo", + "bluzelle.pro", + "token-selfkey.org", + "xn--etherdlta-0f7d.com", + "sether.in", + "xn--ttrex-ysa9423c.com", + "bluzelle.eu", + "bluzelle.site", + "gifto.tech", + "xn--os-g7s.com", + "selfkey.co", + "xn--myeherwalet-ns8exy.com", + "xn--coinelegraph-wk5f.com", + "dai-stablecoin.com", + "eos-token.org", + "venchain.org", + "gatcoins.io", + "deepbrainchain.co", + "myetherwalililet.info", + "myehvterwallet.com", + "myehterumswallet.com", + "nucleusico.com", + "tronlab.tech", + "0x-project.com", + "gift-token-events.mywebcommunity.org", + "funfairtoken.org", + "breadtokenapp.com", + "cloudpetstore.com", + "myethwalilet.com", + "selfkeys.org", + "wallet-ethereum.com", + "xn--methrwallt-26ar0z.com", + "xn--mytherwllet-r8a0c.com", + "bluzelle.promo", + "tokensale.bluzelle.promo", + "cedarlake.org", + "marketingleads4u.com", + "cashaa.co", + "xn--inance-hrb.com", + "wanchain.tech", + "zenprolocol.com", + "ethscan.io", + "etherscan.in", + "props-project.com", + "zilliaq.com", + "reqestnetwork.com", + "etherdelta.pw", + "ethereum-giveaway.org", + "mysimpletoken.org", + "binancc.com", + "blnance.org", + "elherdelta.io", + "xn--hapeshit-ez9c2y.com", + "tenxwallet.co", + "singularitynet.info", + "mytlherwaliet.info", + "iconmainnet.ml", + "tokenselfkey.org", + "xn--myetewallet-cm8e5y.com", + "envione.org", + "myetherwalletet.com", + "claimbcd.com", + "ripiocreditnetwork.in", + "xn--yeterwallet-ml8euo.com", + "ethclassicwallet.info", + "myltherwallet.ru.com", + "etherdella.com", + "xn--yeterwallet-bm8ewn.com", + "singularty.net", + "cloudkitties.co", + "iconfoundation.io", + "kittystat.com", + "gatscoin.io", + "singularitynet.in", + "sale.canay.io", + "canay.io", + "wabicoin.co", + "envion.top", + "sirinslabs.com", + "tronlab.co", + "paxful.com.ng", + "changellyli.com", + "ethereum-code.com", + "xn--plonex-6va6c.com", + "envion.co", + "envion.cc", + "envion.site", + "ethereumchain.info", + "xn--envon-1sa.org", + "xn--btstamp-rfb.net", + "envlon.org", + "envion-ico.org", + "spectivvr.org", + "sirinlbs.com", + "ethereumdoubler.life", + "xn--myetherwllet-fnb.com", + "sirin-labs.com", + "sirin-labs.org", + "envion.one", + "envion.live", + "propsproject.org", + "propsprojects.com", + "decentralland.org", + "xn--metherwalet-ns8ep4b.com", + "redpulsetoken.co", + "propsproject.tech", + "xn--myeterwalet-nl8emj.com", + "powrerledger.com", + "cryptokitties.com", + "sirinlabs.pro", + "sirinlabs.co", + "sirnlabs.com", + "superbitcoin-blockchain.info", + "hellobloom.me", + "mobus.network", + "powrrledger.com", + "xn--myeherwalet-ms8eyy.com", + "qlink-ico.com", + "gatcoin.in", + "tokensale.gamefllp.com", + "gamefllp.com", + "xn--myeherwalle-vici.com", + "xn--myetherwalet-39b.com", + "xn--polonex-ffb.com", + "xn--birex-leba.com", + "raiden-network.org", + "sirintabs.com", + "xn--metherwallt-79a30a.com", + "xn--myethrwllet-2kb3p.com", + "myethlerwallet.eu", + "xn--btrex-b4a.com", + "powerrledger.com", + "xn--cointeegraph-wz4f.com", + "myerherwalet.com", + "qauntstanp.com", + "myetherermwallet.com", + "xn--myethewalet-ns8eqq.com", + "xn--nvion-hza.org", + "nnyetherwallelt.ru.com", + "ico-wacoin.com", + "xn--myeterwalet-nl8enj.com", + "bitcoinsilver.io", + "t0zero.com", + "tokensale.gizer.in", + "gizer.in", + "wabitoken.com", + "gladius.ws", + "xn--metherwallt-8bb4w.com", + "quanttstamp.com", + "gladius.im", + "ethereumstorage.net", + "powerledgerr.com", + "xn--myeherwallet-4j5f.com", + "quamtstamp.com", + "quntstamp.com", + "xn--changely-j59c.com", + "shapeshlft.com", + "coinbasenews.co.uk", + "xn--metherwallet-hmb.com", + "envoin.org", + "powerledger.com", + "bitstannp.net", + "xn--myetherallet-4k5fwn.com", + "xn--coinbas-pya.com", + "requestt.network", + "oracls.network", + "sirinlabs.website", + "powrledger.io", + "slackconfirm.com", + "shape-shift.io", + "oracles-network.org", + "xn--myeherwalle-zb9eia.com", + "blockstack.one", + "urtust.io", + "bittrex.one", + "t0-ico.com", + "xn--cinbase-90a.com", + "xn--metherwalet-ns8ez1g.com", + "tzero-ico.com", + "tzero.su", + "tzero.website", + "blockstack.network", + "ico-tzero.com", + "spectre.site", + "tzero.pw", + "spectre-ai.net", + "xn--waxtokn-y8a.com", + "dmarket.pro", + "bittrex.com11648724328774.cf", + "bittrex.com1987465798.ga", + "autcus.org", + "t-zero.org", + "xn--zero-zxb.com", + "myetherwalletfork.com", + "blokclbain.info", + "datum.sale", + "spectre-ai.org", + "powerledgr.com", + "simpletoken.live", + "sale.simpletoken.live", + "qauntstamp.com", + "raiden-network.com", + "metalpayme.com", + "quantstamp-ico.com", + "myetherwailetclient.com", + "biockchain.biz", + "wallets-blockchain.com", + "golemairdrop.com", + "omisegoairdrop.net", + "blodkchainwallet.info", + "walton-chain.org", + "elite888-ico.com", + "bitflyerjp.com", + "chainlinksmartcontract.com", + "stormtoken.eu", + "omise-go.tech", + "saltending.com", + "stormltoken.com", + "xn--quanttamp-42b.com", + "stormtoken.co", + "storntoken.com", + "stromtoken.com", + "storm-token.com", + "stormtokens.io", + "ether-delta.com", + "ethconnect.live", + "ethconnect.trade", + "xn--bttrex-3va.net", + "quantstamp.com.co", + "wancha.in", + "augur-network.com", + "quantstamp.com.ua", + "myetherwalletmew.com", + "myetherumwalletts.com", + "xn--quanstamp-tmd.com", + "quantsstamps.com", + "changellyl.net", + "xn--myetherwalet-1fb.com", + "myethereumwallets.com", + "xn--myetherwalet-e9b.com", + "quantslamp.com", + "metelpay.com", + "xn--eterdelta-m75d.com", + "linksmartcontract.com", + "myetherwalletaccess.com", + "myetherwalletcheck.com", + "myetherwalletcheck.info", + "myetherwalletconf.com", + "myetherwalleteal.com", + "myetherwalletec.com", + "myetherwalletgeth.com", + "myetherwalletmetamask.com", + "myetherwalletmm.com", + "myetherwalletmy.com", + "myetherwalletnh.com", + "myetherwalletnod.com", + "myetherwalletrr.com", + "myetherwalletrty.com", + "myetherwalletsec.com", + "myetherwalletsecure.com", + "myetherwalletutc.com", + "myetherwalletver.info", + "myetherwalletview.com", + "myetherwalletview.info", + "myetherwalletvrf.com", + "myetherwalletmist.com", + "myetherwalletext.com", + "myetherwalletjson.com", + "mettalpay.com", + "bricklblock.io", + "bittrexy.com", + "utrust.so", + "myethierwallet.org", + "metallpay.com", + "kraken-wallet.com", + "dmarkt.io", + "etherdeltla.com", + "unlversa.io", + "universa.sale", + "mercuryprotocol.live", + "ripiocredlt.network", + "myetlherwa11et.com", + "dentacoin.in", + "rdrtg.com", + "myetherwallet.com.rdrgh.com", + "rdrgh.com", + "ripiocreditnetwork.co", + "riaden.network", + "hydrominer.biz", + "rdrblock.com", + "reqest.network", + "senstoken.com", + "myetherwallat.services", + "ripiocredit.net", + "xn--metherwallet-c06f.com", + "ico.ripiocredits.com", + "ripiocredits.com", + "raidens.network", + "artoken.co", + "myetherwalletlgn.com", + "etherblog.click", + "stormtoken.site", + "httpmyetherwallet.com", + "myetherwalletverify.com", + "byzantiumfork.com", + "myetherwallet.com.byzantiumfork.com", + "www-myethervvallet.com", + "ether24.info", + "block-v.io", + "bittrex.cash", + "shapishift.io", + "ripiocerdit.network", + "rnyetherwa11et.com", + "claimether.com", + "enigmatokensale.com", + "ethereum-org.com", + "mvetnerwallet.com", + "myctherwallet.com", + "myetherwaltet.com", + "myetherwatlet.com", + "privatix.me", + "myetherwalletcnf.com", + "myetherwalletver.com", + "privatix.top", + "privatix.pro", + "privatex.io", + "stormtoken.cc", + "raiden.online", + "stormstoken.com", + "myetereumwallet.com", + "stormtokens.net", + "myetherwalletconf.info", + "storrntoken.com", + "worldofbattles.io", + "ico.worldofbattles.io", + "privatix.live", + "riden.network", + "raidan.network", + "ralden.network", + "mymyetherwallet.com", + "myetherwallets.net", + "myetherwalletverify.info", + "stormxtoken.com", + "myethereum-wallet.com", + "myetherwallet-forkprep.pagedemo.co", + "myetnerwailet.com", + "www-mvetherwallet.com", + "etheirdelta.com", + "myetherwalletiu.com", + "myetherwaiiett.com", + "xn--mytherwalet-cbb87i.com", + "xn--myethrwallet-ivb.co", + "xn--myeterwallet-f1b.com", + "myehterwaliet.com", + "omegaone.co", + "myetherwaiietw.com", + "slack.com.ru", + "polkodot.network", + "request-network.net", + "requestnetwork.live", + "binancie.com", + "first-eth.info", + "myewerthwalliet.com", + "enjincoin.pw", + "xn--bitrex-k17b.com", + "alrswap.io", + "www-request.network", + "myetnenwallet.com", + "www-enigma.co", + "cryptoinsidenews.com", + "air-swap.tech", + "launch.airswap.cc", + "airswap.cc", + "airswaptoken.com", + "launch.airswap.in", + "airswap.in", + "security-steemit.com.mx", + "blockchalnwallet.com", + "blodkchainwallet.com", + "blodkchaln.com", + "myethereumwaiiet.com", + "myethereumwaliet.com", + "myethereumwalilet.com", + "myetherswailet.com", + "myetherswaliet.com", + "myetherswalilet.com", + "myetherwalilett.com", + "myetherwalletl.com", + "myetherwalletww.com", + "myethereunwallet.com", + "myethereumwallct.com", + "myetherwaiieti.com", + "myetherwaiiete.com", + "upfirng.com", + "paypie.net", + "paypie.tech", + "soam.co", + "myetherwaiict.com", + "numerai-token.com", + "www-bankera.com", + "vvanchain.org", + "omisegoairdrop.com", + "xn--enjncoin-41a.io", + "suncontract.su", + "myetherwaiietr.com", + "shapeshiff.io", + "warchain.org", + "myethwallett.com", + "myethervvaliet.com", + "wanchains.org", + "etherparty.in", + "enjincoin.me", + "etiam.io", + "invest.smartlands.tech", + "smartlands.tech", + "enijncoin.io", + "wanchain.network", + "nimiq.su", + "enjincoin.sale", + "tenxwallet.io", + "golem-network.net", + "myyethwallet.ml", + "mywetherwailiet.com", + "omg-omise.com", + "district0x.tech", + "centra-token.com", + "etherdetla.com", + "etnerparty.io", + "etherdelta.su", + "myetherwallett.neocities.org", + "myetherwallet-secure.com", + "myethereumwalletntw.info", + "real-markets.io", + "wallet-ethereum.org", + "request-network.com", + "shapeshifth.io", + "shiapeshift.in", + "coin.red-puise.com", + "ibittreix.com", + "coinkbase.com", + "cindicator.pro", + "myetherwallet.com.ailogin.me", + "eventchain.co", + "kinkik.in", + "myetherumwalletview.com", + "protostokenhub.com", + "coinrbase.com", + "myetherwalletlogin.com", + "omisegotoken.com", + "myethereumwalletntw.com", + "reall.markets", + "cobinhood.org", + "cobinhood.io", + "happy-coin.org", + "bitfinex.com.co", + "bitfienex.com", + "iconn.foundation", + "centra.vip", + "smartcontract.live", + "icon.community", + "air-token.com", + "centra.credit", + "myetherwallet-singin.com", + "smartcontractlink.com", + "shapesshift.io", + "0xtoken.io", + "augurproject.co", + "ethereumus.one", + "myetherumwalet.com", + "myetherwalletsignin.com", + "change-bank.org", + "charge-bank.com", + "myetherwalletsingin.com", + "myetherwalletcontract.com", + "change-bank.io", + "chainlink.tech", + "myetherwallet-confirm.com", + "tokensale.kybernet.network", + "kybernet.network", + "kyberr.network", + "kybernetwork.io", + "myetherwalletconfirm.com", + "kvnuke.github.io", + "kin.kikpro.co", + "myethereumwallet.co.uk", + "tokensale-kyber.network", + "kyber-network.co", + "tokensale.kyber-network.co", + "pyro0.github.io", + "tokensale.kyber.digital", + "kyber.digital", + "omise-go.me", + "my.etherwallet.com.de", + "bepartof.change-bank.co", + "change-bank.co", + "enigma-tokens.co", + "coinbase.com.eslogin.co", + "xn--bittrx-mva.com", + "ethrdelta.github.io", + "etherdellta.com", + "ico-nexus.social", + "red-pulse.tech", + "bitj0b.io", + "xn--bttrex-bwa.com", + "kin-klk.com", + "kin-crowdsale.com", + "ethedelta.com", + "coindash.su", + "myethwallet.co.uk", + "swarm.credit", + "myethereumwallet.uk", + "iconexu.social", + "wanchain.co", + "enigrna.co", + "linknetwork.co", + "qtum-token.com", + "omisego.com.co", + "rivetzintl.org", + "etherdelta.one", + "the-ether.pro", + "etherdelta.gitnub.io", + "kirkik.com", + "monetha.ltd", + "vlberate.io", + "ethereumwallet-kr.info", + "omise-go.org", + "iconexus.social", + "bittirrex.com", + "aventus.pro", + "atlant.solutions", + "aventus.group", + "metamak.io", + "omise.com.co", + "herotokens.io", + "starbase.pro", + "etherdelta.githulb.io", + "herotoken.co", + "kinico.net", + "dmarket.ltd", + "etherdelta.gilthub.io", + "golem-network.com", + "etnerscan.io", + "bllttriex.com", + "monetha.me", + "monetha.co", + "monetha-crowdsale.com", + "starbase.tech", + "aventus-crowdsale.com", + "shapeshift.pro", + "bllttrex.com", + "kickico.co", + "statustoken.im", + "bilttrex.com", + "tenxpay.io", + "bittrex.ltd", + "metalpay.im", + "aragon.im", + "coindash.tech", + "decentraland.tech", + "decentraland.pro", + "status-token.com", + "bittrex.cam", + "enigmatoken.com", + "unocoin.company", + "unocoin.fund", + "0xproject.io", + "0xtoken.com", + "numerai.tech", + "decentraiand.org", + "blockcrein.info", + "blockchealn.info", + "bllookchain.info", + "blockcbhain.info", + "myetherwallet.com.ethpromonodes.com", + "mettamask.io", + "tokenswap.org", + "netherum.com", + "etherexx.org", + "etherume.io", + "ethereum.plus", + "ehtereum.org", + "etereurm.org", + "etheream.com", + "ethererum.org", + "ethereum.io", + "etherdelta-glthub.com", + "cryptoalliance.herokuapp.com", + "bitspark2.com", + "indorsetoken.com", + "iconexus.tk", + "iconexus.ml", + "iconexus.ga", + "iconexus.cf", + "etherwallet.online", + "wallet-ethereum.net", + "bitsdigit.com", + "etherswap.org", + "eos.ac", + "uasfwallet.com", + "ziber.io", + "multiply-ethereum.info", + "bittrex.comze.com", + "karbon.vacau.com", + "etherdelta.gitlhub.io", + "etherdelta.glthub.io", + "digitaldevelopersfund.vacau.com", + "district-0x.io", + "coin-dash.com", + "coindash.ru", + "district0x.net", + "aragonproject.io", + "coin-wallet.info", + "coinswallet.info", + "contribute-status.im", + "ether-api.com", + "ether-wall.com", + "mycoinwallet.net", + "ethereumchamber.com", + "ethereumchamber.net", + "ethereumchest.com", + "ethewallet.com", + "myetherwallet.com.vc", + "myetherwallet.com.pe", + "myetherwallet.us.com", + "myetherwallet.com.u0387831.cp.regruhosting.ru", + "myethereumwallet.su", + "myetherweb.com.de", + "myetherieumwallet.com", + "myetehrwallet.com", + "myeterwalet.com", + "myetherwaiiet.com", + "myetherwallet.info", + "myetherwallet.ch", + "myetherwallet.om", + "myethervallet.com", + "myetherwallet.com.cm", + "myetherwallet.com.co", + "myetherwallet.com.de", + "myetherwallet.com.gl", + "myetherwallet.com.im", + "myetherwallet.com.ua", + "secure-myetherwallet.com", + "update-myetherwallet.com", + "wwwmyetherwallet.com", + "myeatherwallet.com", + "myetharwallet.com", + "myelherwallel.com", + "myetherwaillet.com", + "myetherwaliet.com", + "myetherwallel.com", + "myetherwallet.cam", + "myetherwallet.cc", + "myetherwallet.co", + "myetherwallet.cm", + "myetherwallet.cz", + "myetherwallet.org", + "myetherwallet.tech", + "myetherwallet.top", + "myetherwallet.net", + "myetherwallet.ru.com", + "myetherwallet.com.ru", + "metherwallet.com", + "myetrerwallet.com", + "myetlerwallet.com", + "myethterwallet.com", + "myethwallet.io", + "myethterwallet.co", + "myehterwallet.co", + "myaetherwallet.com", + "myetthterwallet.com", + "myetherwallet.one", + "myelterwallet.com", + "myetherwallet.gdn", + "myetherwallt.com", + "myeterwallet.com", + "myeteherwallet.com", + "myethearwailet.com", + "myetherwallelt.com", + "myetherwallett.com", + "etherwallet.org", + "myetherewallet.com", + "myeherwallet.com", + "myethcrwallet.com", + "myetherwallet.link", + "myetherwallets.com", + "myethearwaillet.com", + "myethearwallet.com", + "myetherawllet.com", + "myethereallet.com", + "myetherswallet.com", + "myetherwalet.com", + "myetherwaller.com", + "myetherwalliet.com", + "myetherwllet.com", + "etherwallet.io", + "myetherwallet.ca", + "myetherwallet.me", + "myetherwallet.ru", + "myetherwallet.xyz", + "myetherwallte.com", + "myethirwallet.com", + "myethrewallet.com", + "etherwallet.net", + "maetherwallet.com", + "meyetherwallet.com", + "my.ether-wallet.pw", + "myehterwallet.com", + "myeitherwallet.com", + "myelherwallet.com", + "myeltherwallet.com", + "myerherwallet.com", + "myethearwalet.com", + "myetherewalle.com", + "myethervvallet.com", + "myetherwallent.com", + "myetherwallet.fm", + "myetherwalllet.com", + "myetherwalltet.com", + "myetherwollet.com", + "myetlherwalet.com", + "myetlherwallet.com", + "rnyetherwallet.com", + "etherclassicwallet.com", + "omg-omise.co", + "omise-go.com", + "omise-go.net", + "omise-omg.com", + "omise-go.io", + "tenx-tech.com", + "bitclaive.com", + "tokensale-tenx.tech", + "ubiqcoin.org", + "metamask.com", + "ethtrade.io", + "myetcwallet.com", + "account-kigo.net", + "bitcoin-wallet.net", + "blocklichan.info", + "bloclkicihan.info", + "coindash.ml", + "eos-bonus.com", + "eos-io.info", + "ether-wallet.net", + "ethereum-wallet.info", + "ethereum-wallet.net", + "ethereumchest.net", + "reservations-kigo.net", + "reservations-lodgix.com", + "secure-liverez.com", + "secure-onerooftop.com", + "settings-liverez.com", + "software-liverez.com", + "software-lodgix.com", + "unhackableetherwallets.com", + "www-myetherwallet.com", + "etherwallet.co.za", + "etherwalletchain.com", + "etherwallets.net", + "etherwallets.nl", + "my-ethwallet.com", + "my.ether-wallet.co", + "myetherwallet.com.am", + "myetherwallet.com.ht", + "myetherwalletcom.com", + "myehterwailet.com", + "xn--myetherwalle-xoc.com", + "xn--myetherwalle-44i.com", + "xn--myetherwalle-xhk.com", + "xn--myetherwallt-cfb.com", + "xn--myetherwallt-6tb.com", + "xn--myetherwallt-xub.com", + "xn--myetherwallt-ovb.com", + "xn--myetherwallt-fwb.com", + "xn--myetherwallt-5wb.com", + "xn--myetherwallt-jzi.com", + "xn--myetherwallt-2ck.com", + "xn--myetherwallt-lok.com", + "xn--myetherwallt-lsl.com", + "xn--myetherwallt-ce6f.com", + "xn--myetherwalet-mcc.com", + "xn--myetherwalet-xhf.com", + "xn--myetherwalet-lcc.com", + "xn--myetherwaet-15ba.com", + "xn--myetherwalet-whf.com", + "xn--myetherwaet-v2ea.com", + "xn--myetherwllet-59a.com", + "xn--myetherwllet-jbb.com", + "xn--myetherwllet-wbb.com", + "xn--myetherwllet-9bb.com", + "xn--myetherwllet-ncb.com", + "xn--myetherwllet-0cb.com", + "xn--myetherwllet-5nb.com", + "xn--myetherwllet-ktd.com", + "xn--myetherwllet-mre.com", + "xn--myetherwllet-76e.com", + "xn--myetherwllet-o0l.com", + "xn--myetherwllet-c45f.com", + "xn--myetherallet-ejn.com", + "xn--myethewallet-4nf.com", + "xn--myethewallet-iof.com", + "xn--myethewallet-mpf.com", + "xn--myethewallet-6bk.com", + "xn--myethewallet-i31f.com", + "xn--myethrwallet-feb.com", + "xn--myethrwallt-fbbf.com", + "xn--myethrwallet-seb.com", + "xn--myethrwallt-rbbf.com", + "xn--myethrwallet-5eb.com", + "xn--myethrwallt-3bbf.com", + "xn--myethrwallet-0tb.com", + "xn--myethrwallt-tpbf.com", + "xn--myethrwallet-rub.com", + "xn--myethrwallt-iqbf.com", + "xn--myethrwallet-ivb.com", + "xn--myethrwallt-6qbf.com", + "xn--myethrwallet-8vb.com", + "xn--myethrwallt-vrbf.com", + "xn--myethrwallet-zwb.com", + "xn--myethrwallt-ksbf.com", + "xn--myethrwallet-dzi.com", + "xn--myethrwallt-wbif.com", + "xn--myethrwallet-wck.com", + "xn--myethrwallt-skjf.com", + "xn--myethrwallet-fok.com", + "xn--myethrwallt-fvjf.com", + "xn--myethrwallet-fsl.com", + "xn--myethrwallt-fwkf.com", + "xn--myethrwallet-5d6f.com", + "xn--myethrwallt-319ef.com", + "xn--myeterwallet-ufk.com", + "xn--myeterwallet-nrl.com", + "xn--myeterwallet-von.com", + "xn--myeterwallet-jl6c.com", + "xn--myeherwallet-ooc.com", + "xn--myeherwalle-6hci.com", + "xn--myeherwallet-v4i.com", + "xn--myeherwalle-zgii.com", + "xn--myeherwallet-ohk.com", + "xn--myeherwalle-6oji.com", + "xn--mytherwallet-ceb.com", + "xn--mythrwallet-cbbc.com", + "xn--mythrwallt-c7acf.com", + "xn--mytherwallet-peb.com", + "xn--mythrwallet-obbc.com", + "xn--mythrwallt-n7acf.com", + "xn--mytherwallet-2eb.com", + "xn--mythrwallet-0bbc.com", + "xn--mythrwallt-y7acf.com", + "xn--mytherwallet-xtb.com", + "xn--mythrwallet-qpbc.com", + "xn--mythrwallt-jlbcf.com", + "xn--mytherwallet-oub.com", + "xn--mythrwallet-fqbc.com", + "xn--mythrwallt-5lbcf.com", + "xn--mythrwallet-3qbc.com", + "xn--mythrwallt-smbcf.com", + "xn--mytherwallet-5vb.com", + "xn--mythrwallet-srbc.com", + "xn--mythrwallt-fnbcf.com", + "xn--mytherwallet-wwb.com", + "xn--mythrwallet-hsbc.com", + "xn--mythrwallt-1nbcf.com", + "xn--mytherwallet-9yi.com", + "xn--mythrwallet-tbic.com", + "xn--mythrwallt-dnhcf.com", + "xn--mytherwallet-tck.com", + "xn--mythrwallet-pkjc.com", + "xn--mythrwallt-lsicf.com", + "xn--mytherwallet-cok.com", + "xn--mythrwallet-cvjc.com", + "xn--mythrwallt-c2icf.com", + "xn--mytherwallet-csl.com", + "xn--mythrwallet-cwkc.com", + "xn--mythrwallt-c0jcf.com", + "xn--mytherwallet-2d6f.com", + "xn--mythrwallet-019ec.com", + "xn--mythrwallt-yq3ecf.com", + "xn--metherwallet-qlb.com", + "xn--metherwallet-1uf.com", + "xn--metherwallet-iyi.com", + "xn--metherwallet-zhk.com", + "xn--metherwallet-3ml.com", + "xn--mytherwallet-fvb.com", + "xn--myetherwallt-7db.com", + "xn--myetherwallt-leb.com", + "xn--myetherwallt-yeb.com", + "xn--yetherwallet-vjf.com", + "xn--yetherwallet-dfk.com", + "xn--yetherwallet-1t1f.com", + "xn--yetherwallet-634f.com", + "xn--myeherwallet-fpc.com", + "xn--myethewallt-crb.com", + "xn--metherwallet-1vc.com", + "xn--myeherwallt-kbb8039g.com", + "xn--myeherwallet-vk5f.com", + "xn--yethewallet-iw8ejl.com", + "xn--bittrx-th8b.com", + "xn--polniex-n0a.com", + "thekey.vin", + "thekey-vip.com", + "digitexftures.com", + "ethzero-wallet.org", + "zeepln.io", + "wepowers.network", + "wepower.vision" + ] +} diff --git a/test/stub/first-time-state.js b/test/stub/first-time-state.js new file mode 100644 index 000000000..c9d5a4fe9 --- /dev/null +++ b/test/stub/first-time-state.js @@ -0,0 +1,14 @@ + +// test and development environment variables +const { createTestProviderTools } = require('../stub/provider') +const providerResultStub = {} +const provider = createTestProviderTools({ scaffold: providerResultStub }).provider +// +// The default state of MetaMask +// +module.exports = { + config: {}, + NetworkController: { + provider, + }, +} diff --git a/test/unit/blacklist-controller-test.js b/test/unit/blacklist-controller-test.js index a9260466f..cbf73d3e5 100644 --- a/test/unit/blacklist-controller-test.js +++ b/test/unit/blacklist-controller-test.js @@ -38,4 +38,4 @@ describe('blacklist controller', function () { assert.equal(result, false) }) }) -}) \ No newline at end of file +}) diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 3fc7f9a98..ac984faf5 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -1,129 +1,103 @@ const assert = require('assert') const sinon = require('sinon') const clone = require('clone') +const nock = require('nock') const MetaMaskController = require('../../app/scripts/metamask-controller') -const firstTimeState = require('../../app/scripts/first-time-state') -const BN = require('ethereumjs-util').BN -const GWEI_BN = new BN('1000000000') +const blacklistJSON = require('../stub/blacklist') +const firstTimeState = require('../stub/first-time-state') describe('MetaMaskController', function () { - const noop = () => {} - const metamaskController = new MetaMaskController({ - showUnconfirmedMessage: noop, - unlockAccountMessage: noop, - showUnapprovedTx: noop, - platform: {}, - encryptor: { - encrypt: function(password, object) { - this.object = object - return Promise.resolve() - }, - decrypt: function () { - return Promise.resolve(this.object) - } - }, - // initial state - initState: clone(firstTimeState), - }) + let metamaskController + const sandbox = sinon.sandbox.create() + const noop = () => { } beforeEach(function () { - // sinon allows stubbing methods that are easily verified - this.sinon = sinon.sandbox.create() + + nock('https://api.infura.io') + .persist() + .get('/v2/blacklist') + .reply(200, blacklistJSON) + + nock('https://rinkeby.infura.io') + .persist() + .post('/metamask') + .reply(200) + + metamaskController = new MetaMaskController({ + showUnapprovedTx: noop, + encryptor: { + encrypt: function (password, object) { + this.object = object + return Promise.resolve() + }, + decrypt: function () { + return Promise.resolve(this.object) + }, + }, + initState: clone(firstTimeState), + }) + sandbox.spy(metamaskController.keyringController, 'createNewVaultAndKeychain') + sandbox.spy(metamaskController.keyringController, 'createNewVaultAndRestore') }) afterEach(function () { - // sinon requires cleanup otherwise it will overwrite context - this.sinon.restore() + nock.cleanAll() + sandbox.restore() }) - describe('Metamask Controller', function () { - assert(metamaskController) - - beforeEach(function () { - sinon.spy(metamaskController.keyringController, 'createNewVaultAndKeychain') - sinon.spy(metamaskController.keyringController, 'createNewVaultAndRestore') - }) - - afterEach(function () { - metamaskController.keyringController.createNewVaultAndKeychain.restore() - metamaskController.keyringController.createNewVaultAndRestore.restore() - }) - - describe('#getGasPrice', function () { - it('gives the 50th percentile lowest accepted gas price from recentBlocksController', async function () { - const realRecentBlocksController = metamaskController.recentBlocksController - metamaskController.recentBlocksController = { - store: { - getState: () => { - return { - recentBlocks: [ - { gasPrices: [ '0x3b9aca00', '0x174876e800'] }, - { gasPrices: [ '0x3b9aca00', '0x174876e800'] }, - { gasPrices: [ '0x174876e800', '0x174876e800' ]}, - { gasPrices: [ '0x174876e800', '0x174876e800' ]}, - ] - } - } - } - } - - const gasPrice = metamaskController.getGasPrice() - assert.equal(gasPrice, '0x3b9aca00', 'accurately estimates 50th percentile accepted gas price') - - metamaskController.recentBlocksController = realRecentBlocksController - }) - - it('gives the 1 gwei price if no blocks have been seen.', async function () { - const realRecentBlocksController = metamaskController.recentBlocksController - metamaskController.recentBlocksController = { - store: { - getState: () => { - return { - recentBlocks: [] - } + describe('#getGasPrice', function () { + it('gives the 50th percentile lowest accepted gas price from recentBlocksController', async function () { + const realRecentBlocksController = metamaskController.recentBlocksController + metamaskController.recentBlocksController = { + store: { + getState: () => { + return { + recentBlocks: [ + { gasPrices: [ '0x3b9aca00', '0x174876e800'] }, + { gasPrices: [ '0x3b9aca00', '0x174876e800'] }, + { gasPrices: [ '0x174876e800', '0x174876e800' ]}, + { gasPrices: [ '0x174876e800', '0x174876e800' ]}, + ], } - } - } - - const gasPrice = metamaskController.getGasPrice() - assert.equal(gasPrice, '0x' + GWEI_BN.toString(16), 'defaults to 1 gwei') + }, + }, + } - metamaskController.recentBlocksController = realRecentBlocksController - }) + const gasPrice = metamaskController.getGasPrice() + assert.equal(gasPrice, '0x3b9aca00', 'accurately estimates 50th percentile accepted gas price') + metamaskController.recentBlocksController = realRecentBlocksController }) + }) - describe('#createNewVaultAndKeychain', function () { - it('can only create new vault on keyringController once', async function () { - const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity') - + describe('#createNewVaultAndKeychain', function () { + it('can only create new vault on keyringController once', async function () { + const selectStub = sandbox.stub(metamaskController, 'selectFirstIdentity') - const password = 'a-fake-password' + const password = 'a-fake-password' - const first = await metamaskController.createNewVaultAndKeychain(password) - const second = await metamaskController.createNewVaultAndKeychain(password) + await metamaskController.createNewVaultAndKeychain(password) + await metamaskController.createNewVaultAndKeychain(password) - assert(metamaskController.keyringController.createNewVaultAndKeychain.calledOnce) + assert(metamaskController.keyringController.createNewVaultAndKeychain.calledOnce) - selectStub.reset() - }) + selectStub.reset() }) + }) + + describe('#createNewVaultAndRestore', function () { + it('should be able to call newVaultAndRestore despite a mistake.', async function () { + + const password = 'what-what-what' + const wrongSeed = 'debris dizzy just program just float decrease vacant alarm reduce speak stadiu' + const rightSeed = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium' + await metamaskController.createNewVaultAndRestore(password, wrongSeed) + .catch((e) => { + return + }) + await metamaskController.createNewVaultAndRestore(password, rightSeed) - describe('#createNewVaultAndRestore', function () { - it('should be able to call newVaultAndRestore despite a mistake.', async function () { - // const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity') - - const password = 'what-what-what' - const wrongSeed = 'debris dizzy just program just float decrease vacant alarm reduce speak stadiu' - const rightSeed = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium' - const first = await metamaskController.createNewVaultAndRestore(password, wrongSeed) - .catch((e) => { - return - }) - const second = await metamaskController.createNewVaultAndRestore(password, rightSeed) - - assert(metamaskController.keyringController.createNewVaultAndRestore.calledTwice) - }) + assert(metamaskController.keyringController.createNewVaultAndRestore.calledTwice) }) }) }) diff --git a/test/unit/network-contoller-test.js b/test/unit/network-contoller-test.js index 0b3b5adeb..fe3b9e66a 100644 --- a/test/unit/network-contoller-test.js +++ b/test/unit/network-contoller-test.js @@ -1,4 +1,5 @@ const assert = require('assert') +const nock = require('nock') const NetworkController = require('../../app/scripts/controllers/network') describe('# Network Controller', function () { @@ -8,6 +9,9 @@ describe('# Network Controller', function () { } beforeEach(function () { + nock('https://api.infura.io') + .get('/*/') + .reply(200, {}) networkController = new NetworkController({ provider: { type: 'rinkeby', -- cgit v1.2.3 From 8f7094a73d4ca5879e8290e3b1aefdc42397767d Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Thu, 15 Feb 2018 09:54:22 -0800 Subject: Network controller nock --- test/unit/network-contoller-test.js | 40 +++++++++++++++---------------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'test') diff --git a/test/unit/network-contoller-test.js b/test/unit/network-contoller-test.js index fe3b9e66a..cd8c345c5 100644 --- a/test/unit/network-contoller-test.js +++ b/test/unit/network-contoller-test.js @@ -2,28 +2,37 @@ const assert = require('assert') const nock = require('nock') const NetworkController = require('../../app/scripts/controllers/network') +const { createTestProviderTools } = require('../stub/provider') +const providerResultStub = {} +const provider = createTestProviderTools({ scaffold: providerResultStub }).provider + describe('# Network Controller', function () { let networkController + const noop = () => {} const networkControllerProviderInit = { getAccounts: () => {}, } beforeEach(function () { + nock('https://api.infura.io') .get('/*/') - .reply(200, {}) + .reply(200) + + nock('https://rinkeby.infura.io') + .post('/metamask') + .reply(200) + networkController = new NetworkController({ - provider: { - type: 'rinkeby', - }, + provider, }) - networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor) + networkController.initializeProvider(networkControllerProviderInit, provider) }) describe('network', function () { describe('#provider', function () { it('provider should be updatable without reassignment', function () { - networkController.initializeProvider(networkControllerProviderInit, dummyProviderConstructor) + networkController.initializeProvider(networkControllerProviderInit, provider) const proxy = networkController._proxy proxy.setTarget({ test: true, on: () => {} }) assert.ok(proxy.test) @@ -68,21 +77,4 @@ describe('# Network Controller', function () { }) }) }) -}) - -function dummyProviderConstructor() { - return { - // provider - sendAsync: noop, - // block tracker - _blockTracker: {}, - start: noop, - stop: noop, - on: noop, - addListener: noop, - once: noop, - removeAllListeners: noop, - } -} - -function noop() {} \ No newline at end of file +}) \ No newline at end of file -- cgit v1.2.3 From b2f53fa35481006cba37d89ebf4c7a866be4f125 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 27 Feb 2018 15:50:49 -0800 Subject: Revert initializing first-time-state --- test/stub/first-time-state.js | 14 -------------- test/unit/metamask-controller-test.js | 6 +++--- 2 files changed, 3 insertions(+), 17 deletions(-) delete mode 100644 test/stub/first-time-state.js (limited to 'test') diff --git a/test/stub/first-time-state.js b/test/stub/first-time-state.js deleted file mode 100644 index c9d5a4fe9..000000000 --- a/test/stub/first-time-state.js +++ /dev/null @@ -1,14 +0,0 @@ - -// test and development environment variables -const { createTestProviderTools } = require('../stub/provider') -const providerResultStub = {} -const provider = createTestProviderTools({ scaffold: providerResultStub }).provider -// -// The default state of MetaMask -// -module.exports = { - config: {}, - NetworkController: { - provider, - }, -} diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index ac984faf5..adeca9b5f 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -4,7 +4,7 @@ const clone = require('clone') const nock = require('nock') const MetaMaskController = require('../../app/scripts/metamask-controller') const blacklistJSON = require('../stub/blacklist') -const firstTimeState = require('../stub/first-time-state') +const firstTimeState = require('../../app/scripts/first-time-state') describe('MetaMaskController', function () { let metamaskController @@ -18,9 +18,9 @@ describe('MetaMaskController', function () { .get('/v2/blacklist') .reply(200, blacklistJSON) - nock('https://rinkeby.infura.io') + nock('https://api.infura.io') .persist() - .post('/metamask') + .get(/.*/) .reply(200) metamaskController = new MetaMaskController({ -- cgit v1.2.3 From f9de87af51ccb1190ca93e524de24f8a32ea3d9e Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 27 Feb 2018 15:51:14 -0800 Subject: Using noop to not lose it --- test/unit/network-contoller-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/network-contoller-test.js b/test/unit/network-contoller-test.js index cd8c345c5..51ad09f87 100644 --- a/test/unit/network-contoller-test.js +++ b/test/unit/network-contoller-test.js @@ -10,7 +10,7 @@ describe('# Network Controller', function () { let networkController const noop = () => {} const networkControllerProviderInit = { - getAccounts: () => {}, + getAccounts: noop, } beforeEach(function () { -- cgit v1.2.3 From 92453f8715b78c0e6e2cdb9b2e1cfe48c0b013ad Mon Sep 17 00:00:00 2001 From: Csaba Solya Date: Sat, 3 Mar 2018 00:32:57 +0100 Subject: seed phrase verifier --- test/unit/seed-phrase-verifier-test.js | 136 +++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 test/unit/seed-phrase-verifier-test.js (limited to 'test') diff --git a/test/unit/seed-phrase-verifier-test.js b/test/unit/seed-phrase-verifier-test.js new file mode 100644 index 000000000..a7a463dd3 --- /dev/null +++ b/test/unit/seed-phrase-verifier-test.js @@ -0,0 +1,136 @@ +const assert = require('assert') +const clone = require('clone') +const KeyringController = require('eth-keyring-controller') +const firstTimeState = require('../../app/scripts/first-time-state') +const seedPhraseVerifier = require('../../app/scripts/lib/seed-phrase-verifier') +const mockEncryptor = require('../lib/mock-encryptor') + +describe('SeedPhraseVerifier', function () { + + describe('verifyAccounts', function () { + + var password = 'passw0rd1' + let hdKeyTree = 'HD Key Tree' + + it('should be able to verify created account with seed words', async function () { + + let keyringController = new KeyringController({ + initState: clone(firstTimeState), + encryptor: mockEncryptor, + }) + assert(keyringController) + + let vault = await keyringController.createNewVaultAndKeychain(password) + let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] + + let createdAccounts = await primaryKeyring.getAccounts() + assert.equal(createdAccounts.length, 1) + + let serialized = await primaryKeyring.serialize() + let seedWords = serialized.mnemonic + assert.notEqual(seedWords.length, 0) + + let result = await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords) + }) + + it('should return error with good but different seed words', async function () { + + let keyringController = new KeyringController({ + initState: clone(firstTimeState), + encryptor: mockEncryptor, + }) + assert(keyringController) + + let vault = await keyringController.createNewVaultAndKeychain(password) + let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] + + let createdAccounts = await primaryKeyring.getAccounts() + assert.equal(createdAccounts.length, 1) + + let serialized = await primaryKeyring.serialize() + let seedWords = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium' + + try { + let result = await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords) + assert.fail("Should reject") + } catch (err) { + assert.ok(err.message.indexOf('Not identical accounts!') >= 0, 'Wrong error message') + } + }) + + it('should return error with undefined existing accounts', async function () { + + let keyringController = new KeyringController({ + initState: clone(firstTimeState), + encryptor: mockEncryptor, + }) + assert(keyringController) + + let vault = await keyringController.createNewVaultAndKeychain(password) + let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] + + let createdAccounts = await primaryKeyring.getAccounts() + assert.equal(createdAccounts.length, 1) + + let serialized = await primaryKeyring.serialize() + let seedWords = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium' + + try { + let result = await seedPhraseVerifier.verifyAccounts(undefined, seedWords) + assert.fail("Should reject") + } catch (err) { + assert.equal(err.message, 'No created accounts defined.') + } + }) + + it('should return error with empty accounts array', async function () { + + let keyringController = new KeyringController({ + initState: clone(firstTimeState), + encryptor: mockEncryptor, + }) + assert(keyringController) + + let vault = await keyringController.createNewVaultAndKeychain(password) + let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] + + let createdAccounts = await primaryKeyring.getAccounts() + assert.equal(createdAccounts.length, 1) + + let serialized = await primaryKeyring.serialize() + let seedWords = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium' + + try { + let result = await seedPhraseVerifier.verifyAccounts([], seedWords) + assert.fail("Should reject") + } catch (err) { + assert.equal(err.message, 'No created accounts defined.') + } + }) + + it('should be able to verify more than one created account with seed words', async function () { + + let keyringController = new KeyringController({ + initState: clone(firstTimeState), + encryptor: mockEncryptor, + }) + assert(keyringController) + + let vault = await keyringController.createNewVaultAndKeychain(password) + + let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] + + const keyState = await keyringController.addNewAccount(primaryKeyring) + const keyState2 = await keyringController.addNewAccount(primaryKeyring) + + let createdAccounts = await primaryKeyring.getAccounts() + assert.equal(createdAccounts.length, 3) + + let serialized = await primaryKeyring.serialize() + let seedWords = serialized.mnemonic + assert.notEqual(seedWords.length, 0) + + let result = await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords) + }) + }) +}) -- cgit v1.2.3 From 3e05b693dbf55ea7ecb791e8f31b7599a6b89ffd Mon Sep 17 00:00:00 2001 From: Csaba Solya Date: Sat, 3 Mar 2018 14:11:02 +0100 Subject: verify addresses regardless case --- test/unit/seed-phrase-verifier-test.js | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'test') diff --git a/test/unit/seed-phrase-verifier-test.js b/test/unit/seed-phrase-verifier-test.js index a7a463dd3..3e9acfa82 100644 --- a/test/unit/seed-phrase-verifier-test.js +++ b/test/unit/seed-phrase-verifier-test.js @@ -33,6 +33,50 @@ describe('SeedPhraseVerifier', function () { let result = await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords) }) + it('should be able to verify created account (upper case) with seed words', async function () { + + let keyringController = new KeyringController({ + initState: clone(firstTimeState), + encryptor: mockEncryptor, + }) + assert(keyringController) + + let vault = await keyringController.createNewVaultAndKeychain(password) + let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] + + let createdAccounts = await primaryKeyring.getAccounts() + assert.equal(createdAccounts.length, 1) + let upperCaseAccounts = [createdAccounts[0].toUpperCase()] + + let serialized = await primaryKeyring.serialize() + let seedWords = serialized.mnemonic + assert.notEqual(seedWords.length, 0) + + let result = await seedPhraseVerifier.verifyAccounts(upperCaseAccounts, seedWords) + }) + + it('should be able to verify created account (lower case) with seed words', async function () { + + let keyringController = new KeyringController({ + initState: clone(firstTimeState), + encryptor: mockEncryptor, + }) + assert(keyringController) + + let vault = await keyringController.createNewVaultAndKeychain(password) + let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] + + let createdAccounts = await primaryKeyring.getAccounts() + assert.equal(createdAccounts.length, 1) + let lowerCaseAccounts = [createdAccounts[0].toLowerCase()] + + let serialized = await primaryKeyring.serialize() + let seedWords = serialized.mnemonic + assert.notEqual(seedWords.length, 0) + + let result = await seedPhraseVerifier.verifyAccounts(lowerCaseAccounts, seedWords) + }) + it('should return error with good but different seed words', async function () { let keyringController = new KeyringController({ -- cgit v1.2.3 From 2b86d65d0c3266e8ddfe814abe1d1755fbf23fda Mon Sep 17 00:00:00 2001 From: Csaba Solya Date: Sat, 3 Mar 2018 22:08:10 +0100 Subject: verify seedwords on log in --- test/unit/seed-phrase-verifier-test.js | 48 ++++++---------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) (limited to 'test') diff --git a/test/unit/seed-phrase-verifier-test.js b/test/unit/seed-phrase-verifier-test.js index 3e9acfa82..654fb5994 100644 --- a/test/unit/seed-phrase-verifier-test.js +++ b/test/unit/seed-phrase-verifier-test.js @@ -9,16 +9,20 @@ describe('SeedPhraseVerifier', function () { describe('verifyAccounts', function () { - var password = 'passw0rd1' + let password = 'passw0rd1' let hdKeyTree = 'HD Key Tree' - it('should be able to verify created account with seed words', async function () { - - let keyringController = new KeyringController({ + let keyringController + beforeEach(function () { + keyringController = new KeyringController({ initState: clone(firstTimeState), encryptor: mockEncryptor, }) + assert(keyringController) + }) + + it('should be able to verify created account with seed words', async function () { let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -35,12 +39,6 @@ describe('SeedPhraseVerifier', function () { it('should be able to verify created account (upper case) with seed words', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -57,12 +55,6 @@ describe('SeedPhraseVerifier', function () { it('should be able to verify created account (lower case) with seed words', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -79,12 +71,6 @@ describe('SeedPhraseVerifier', function () { it('should return error with good but different seed words', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -104,12 +90,6 @@ describe('SeedPhraseVerifier', function () { it('should return error with undefined existing accounts', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -129,12 +109,6 @@ describe('SeedPhraseVerifier', function () { it('should return error with empty accounts array', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -154,12 +128,6 @@ describe('SeedPhraseVerifier', function () { it('should be able to verify more than one created account with seed words', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] -- cgit v1.2.3 From 8fde208f0b1da39ccd63b5f256902786e73e9368 Mon Sep 17 00:00:00 2001 From: Csaba Solya Date: Sun, 4 Mar 2018 08:57:55 +0100 Subject: move more test code to beforeEach --- test/unit/seed-phrase-verifier-test.js | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/unit/seed-phrase-verifier-test.js b/test/unit/seed-phrase-verifier-test.js index 654fb5994..4e314806b 100644 --- a/test/unit/seed-phrase-verifier-test.js +++ b/test/unit/seed-phrase-verifier-test.js @@ -13,20 +13,23 @@ describe('SeedPhraseVerifier', function () { let hdKeyTree = 'HD Key Tree' let keyringController - beforeEach(function () { + let vault + let primaryKeyring + + beforeEach(async function () { keyringController = new KeyringController({ initState: clone(firstTimeState), encryptor: mockEncryptor, }) assert(keyringController) + + vault = await keyringController.createNewVaultAndKeychain(password) + primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] }) it('should be able to verify created account with seed words', async function () { - let vault = await keyringController.createNewVaultAndKeychain(password) - let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] - let createdAccounts = await primaryKeyring.getAccounts() assert.equal(createdAccounts.length, 1) @@ -39,11 +42,9 @@ describe('SeedPhraseVerifier', function () { it('should be able to verify created account (upper case) with seed words', async function () { - let vault = await keyringController.createNewVaultAndKeychain(password) - let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] - let createdAccounts = await primaryKeyring.getAccounts() assert.equal(createdAccounts.length, 1) + let upperCaseAccounts = [createdAccounts[0].toUpperCase()] let serialized = await primaryKeyring.serialize() @@ -55,9 +56,6 @@ describe('SeedPhraseVerifier', function () { it('should be able to verify created account (lower case) with seed words', async function () { - let vault = await keyringController.createNewVaultAndKeychain(password) - let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] - let createdAccounts = await primaryKeyring.getAccounts() assert.equal(createdAccounts.length, 1) let lowerCaseAccounts = [createdAccounts[0].toLowerCase()] @@ -71,9 +69,6 @@ describe('SeedPhraseVerifier', function () { it('should return error with good but different seed words', async function () { - let vault = await keyringController.createNewVaultAndKeychain(password) - let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] - let createdAccounts = await primaryKeyring.getAccounts() assert.equal(createdAccounts.length, 1) @@ -90,9 +85,6 @@ describe('SeedPhraseVerifier', function () { it('should return error with undefined existing accounts', async function () { - let vault = await keyringController.createNewVaultAndKeychain(password) - let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] - let createdAccounts = await primaryKeyring.getAccounts() assert.equal(createdAccounts.length, 1) @@ -109,9 +101,6 @@ describe('SeedPhraseVerifier', function () { it('should return error with empty accounts array', async function () { - let vault = await keyringController.createNewVaultAndKeychain(password) - let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] - let createdAccounts = await primaryKeyring.getAccounts() assert.equal(createdAccounts.length, 1) @@ -128,10 +117,6 @@ describe('SeedPhraseVerifier', function () { it('should be able to verify more than one created account with seed words', async function () { - let vault = await keyringController.createNewVaultAndKeychain(password) - - let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] - const keyState = await keyringController.addNewAccount(primaryKeyring) const keyState2 = await keyringController.addNewAccount(primaryKeyring) -- cgit v1.2.3 From cad5f5f0009713a1101194d964af7a1620ea158c Mon Sep 17 00:00:00 2001 From: Jeffrey Tong Date: Wed, 7 Mar 2018 10:24:36 -0800 Subject: fix typo in tests and tx-state-manager --- test/unit/message-manager-test.js | 4 ++-- test/unit/tx-state-manager-test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/unit/message-manager-test.js b/test/unit/message-manager-test.js index 9b76241ed..5e7039841 100644 --- a/test/unit/message-manager-test.js +++ b/test/unit/message-manager-test.js @@ -1,11 +1,11 @@ const assert = require('assert') -const MessageManger = require('../../app/scripts/lib/message-manager') +const MessageManager = require('../../app/scripts/lib/message-manager') describe('Message Manager', function () { let messageManager beforeEach(function () { - messageManager = new MessageManger() + messageManager = new MessageManager() }) describe('#getMsgList', function () { diff --git a/test/unit/tx-state-manager-test.js b/test/unit/tx-state-manager-test.js index 02dc52967..220bf501f 100644 --- a/test/unit/tx-state-manager-test.js +++ b/test/unit/tx-state-manager-test.js @@ -5,7 +5,7 @@ const TxStateManager = require('../../app/scripts/lib/tx-state-manager') const txStateHistoryHelper = require('../../app/scripts/lib/tx-state-history-helper') const noop = () => true -describe('TransactionStateManger', function () { +describe('TransactionStateManager', function () { let txStateManager const currentNetworkId = 42 const otherNetworkId = 2 @@ -281,4 +281,4 @@ describe('TransactionStateManger', function () { }) }) -}) \ No newline at end of file +}) -- cgit v1.2.3 From ae795c977012f152ae96b160fcb8c1e3996904fa Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 9 Mar 2018 11:20:18 -0800 Subject: Persist rinkeby.infura.io and clean nock after --- test/unit/network-contoller-test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/unit/network-contoller-test.js b/test/unit/network-contoller-test.js index 51ad09f87..dd0b52365 100644 --- a/test/unit/network-contoller-test.js +++ b/test/unit/network-contoller-test.js @@ -15,11 +15,8 @@ describe('# Network Controller', function () { beforeEach(function () { - nock('https://api.infura.io') - .get('/*/') - .reply(200) - nock('https://rinkeby.infura.io') + .persist() .post('/metamask') .reply(200) @@ -29,6 +26,11 @@ describe('# Network Controller', function () { networkController.initializeProvider(networkControllerProviderInit, provider) }) + + afterEach(function () { + nock.cleanAll() + }) + describe('network', function () { describe('#provider', function () { it('provider should be updatable without reassignment', function () { -- cgit v1.2.3 From 74502296ed22edd5300ea74fd7b483fab0736729 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sat, 10 Mar 2018 11:09:45 -0800 Subject: ci - split integration tests into parallel firefox and chrome runs --- test/base.conf.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/base.conf.js b/test/base.conf.js index 82b9d8eec..adb5357e8 100644 --- a/test/base.conf.js +++ b/test/base.conf.js @@ -46,7 +46,9 @@ module.exports = function(config) { // start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['Chrome', 'Firefox'], + browsers: process.env.browsers ? + JSON.parse(process.env.browsers) + : ['Chrome', 'Firefox'], // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits -- cgit v1.2.3 From 0419276958a168f2d7b75c11cfe8d14cf5f39514 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sun, 11 Mar 2018 14:52:29 -0700 Subject: test - poll for element instead of manual timeouts --- test/integration/lib/add-token.js | 73 +++++++-------------- test/integration/lib/first-time.js | 80 ++++++++--------------- test/integration/lib/send-new-ui.js | 127 ++++++++++++------------------------ test/lib/util.js | 53 +++++++++++++++ 4 files changed, 144 insertions(+), 189 deletions(-) create mode 100644 test/lib/util.js (limited to 'test') diff --git a/test/integration/lib/add-token.js b/test/integration/lib/add-token.js index dd4251cc4..42ed28dca 100644 --- a/test/integration/lib/add-token.js +++ b/test/integration/lib/add-token.js @@ -1,4 +1,9 @@ const reactTriggerChange = require('react-trigger-change') +const { + timeout, + queryAsync, + findAsync, +} = require('../../lib/util') QUnit.module('Add token flow') @@ -13,74 +18,60 @@ QUnit.test('successful add token flow', (assert) => { }) async function runAddTokenFlowTest (assert, done) { - const selectState = $('select') + const selectState = await queryAsync($, 'select') selectState.val('add token') reactTriggerChange(selectState[0]) - await timeout(2000) - // Check that no tokens have been added assert.ok($('.token-list-item').length === 0, 'no tokens added') // Go to Add Token screen - let addTokenButton = $('button.btn-clear.wallet-view__add-token-button') + let addTokenButton = await queryAsync($, 'button.btn-clear.wallet-view__add-token-button') assert.ok(addTokenButton[0], 'add token button present') addTokenButton[0].click() - await timeout(1000) - // Verify Add Token screen - let addTokenWrapper = $('.add-token__wrapper') + let addTokenWrapper = await queryAsync($, '.add-token__wrapper') assert.ok(addTokenWrapper[0], 'add token wrapper renders') - let addTokenTitle = $('.add-token__title') + let addTokenTitle = await queryAsync($, '.add-token__title') assert.equal(addTokenTitle[0].textContent, 'Add Token', 'add token title is correct') // Cancel Add Token - const cancelAddTokenButton = $('button.btn-cancel.add-token__button') + const cancelAddTokenButton = await queryAsync($, 'button.btn-cancel.add-token__button') assert.ok(cancelAddTokenButton[0], 'cancel add token button present') cancelAddTokenButton.click() - await timeout(1000) - assert.ok($('.wallet-view')[0], 'cancelled and returned to account detail wallet view') // Return to Add Token Screen - addTokenButton = $('button.btn-clear.wallet-view__add-token-button') + addTokenButton = await queryAsync($, 'button.btn-clear.wallet-view__add-token-button') assert.ok(addTokenButton[0], 'add token button present') addTokenButton[0].click() - await timeout(1000) - // Verify Add Token Screen - addTokenWrapper = $('.add-token__wrapper') - addTokenTitle = $('.add-token__title') + addTokenWrapper = await queryAsync($, '.add-token__wrapper') + addTokenTitle = await queryAsync($, '.add-token__title') assert.ok(addTokenWrapper[0], 'add token wrapper renders') assert.equal(addTokenTitle[0].textContent, 'Add Token', 'add token title is correct') // Search for token - const searchInput = $('input.add-token__input') + const searchInput = await queryAsync($, 'input.add-token__input') searchInput.val('a') reactTriggerChange(searchInput[0]) - await timeout() - // Click token to add - const tokenWrapper = $('div.add-token__token-wrapper') + const tokenWrapper = await queryAsync($, 'div.add-token__token-wrapper') assert.ok(tokenWrapper[0], 'token found') const tokenImageProp = tokenWrapper.find('.add-token__token-icon').css('background-image') const tokenImageUrl = tokenImageProp.slice(5, -2) tokenWrapper[0].click() - await timeout() - // Click Next button - let nextButton = $('button.btn-clear.add-token__button') + let nextButton = await queryAsync($, 'button.btn-clear.add-token__button') assert.equal(nextButton[0].textContent, 'Next', 'next button rendered') nextButton[0].click() - await timeout() - // Confirm Add token assert.equal( $('.add-token__description')[0].textContent, @@ -90,47 +81,35 @@ async function runAddTokenFlowTest (assert, done) { assert.ok($('button.btn-clear.add-token__button')[0], 'confirm add token button found') $('button.btn-clear.add-token__button')[0].click() - await timeout(2000) - // Verify added token image - let heroBalance = $('.hero-balance') + let heroBalance = await queryAsync($, '.hero-balance') assert.ok(heroBalance, 'rendered hero balance') assert.ok(tokenImageUrl.indexOf(heroBalance.find('img').attr('src')) > -1, 'token added') // Return to Add Token Screen - addTokenButton = $('button.btn-clear.wallet-view__add-token-button') + addTokenButton = await queryAsync($, 'button.btn-clear.wallet-view__add-token-button') assert.ok(addTokenButton[0], 'add token button present') addTokenButton[0].click() - await timeout(1000) - - const addCustom = $('.add-token__add-custom') + const addCustom = await queryAsync($, '.add-token__add-custom') assert.ok(addCustom[0], 'add custom token button present') addCustom[0].click() - await timeout() - // Input token contract address - const customInput = $('input.add-token__add-custom-input') + const customInput = await queryAsync($, 'input.add-token__add-custom-input') customInput.val('0x177af043D3A1Aed7cc5f2397C70248Fc6cDC056c') reactTriggerChange(customInput[0]) - await timeout(1000) - // Click Next button - nextButton = $('button.btn-clear.add-token__button') + nextButton = await queryAsync($, 'button.btn-clear.add-token__button') assert.equal(nextButton[0].textContent, 'Next', 'next button rendered') nextButton[0].click() - await timeout(1000) - // Verify symbol length error since contract address won't return symbol - const errorMessage = $('.add-token__add-custom-error-message') + const errorMessage = await queryAsync($, '.add-token__add-custom-error-message') assert.ok(errorMessage[0], 'error rendered') $('button.btn-cancel.add-token__button')[0].click() - await timeout(2000) - // // Confirm Add token // assert.equal( // $('.add-token__description')[0].textContent, @@ -141,13 +120,7 @@ async function runAddTokenFlowTest (assert, done) { // $('button.btn-clear.add-token__button')[0].click() // // Verify added token image - // heroBalance = $('.hero-balance') + // heroBalance = await queryAsync($, '.hero-balance') // assert.ok(heroBalance, 'rendered hero balance') // assert.ok(heroBalance.find('.identicon')[0], 'token added') } - -function timeout (time) { - return new Promise((resolve, reject) => { - setTimeout(resolve, time || 1500) - }) -} diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index 764eae47c..052d89518 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -1,6 +1,10 @@ const reactTriggerChange = require('react-trigger-change') const PASSWORD = 'password123' const runMascaraFirstTimeTest = require('./mascara-first-time') +const { + timeout, + findAsync, +} = require('../../lib/util') QUnit.module('first time usage') @@ -21,20 +25,19 @@ async function runFirstTimeUsageTest(assert, done) { selectState.val('first time') reactTriggerChange(selectState[0]) - await timeout(2000) const app = $('#app-content') // recurse notices while (true) { - const button = app.find('button') + const button = await findAsync(app, 'button') if (button.html() === 'Accept') { // still notices to accept - const termsPage = app.find('.markdown')[0] + const termsPageRaw = await findAsync(app, '.markdown') + const termsPage = (await findAsync(app, '.markdown'))[0] + console.log('termsPageRaw', termsPageRaw) termsPage.scrollTop = termsPage.scrollHeight - await timeout() console.log('Clearing notice') button.click() - await timeout() } else { // exit loop console.log('No more notices...') @@ -42,97 +45,68 @@ async function runFirstTimeUsageTest(assert, done) { } } - await timeout() - // Scroll through terms - const title = app.find('h1')[0] + const title = (await findAsync(app, 'h1'))[0] assert.equal(title.textContent, 'MetaMask', 'title screen') // enter password - const pwBox = app.find('#password-box')[0] - const confBox = app.find('#password-box-confirm')[0] + const pwBox = (await findAsync(app, '#password-box'))[0] + const confBox = (await findAsync(app, '#password-box-confirm'))[0] pwBox.value = PASSWORD confBox.value = PASSWORD - await timeout() - // create vault - const createButton = app.find('button.primary')[0] + const createButton = (await findAsync(app, 'button.primary'))[0] createButton.click() - await timeout(3000) - - const created = app.find('h3')[0] + await timeout() + const created = (await findAsync(app, 'h3'))[0] assert.equal(created.textContent, 'Vault Created', 'Vault created screen') // Agree button - const button = app.find('button')[0] + const button = (await findAsync(app, 'button'))[0] assert.ok(button, 'button present') button.click() - await timeout(1000) - - const detail = app.find('.account-detail-section')[0] + const detail = (await findAsync(app, '.account-detail-section'))[0] assert.ok(detail, 'Account detail section loaded.') - const sandwich = app.find('.sandwich-expando')[0] + const sandwich = (await findAsync(app, '.sandwich-expando'))[0] sandwich.click() - await timeout() - - const menu = app.find('.menu-droppo')[0] + const menu = (await findAsync(app, '.menu-droppo'))[0] const children = menu.children const logout = children[2] assert.ok(logout, 'Lock menu item found') logout.click() - await timeout(1000) - - const pwBox2 = app.find('#password-box')[0] + const pwBox2 = (await findAsync(app, '#password-box'))[0] pwBox2.value = PASSWORD - const createButton2 = app.find('button.primary')[0] + const createButton2 = (await findAsync(app, 'button.primary'))[0] createButton2.click() - await timeout(1000) - - const detail2 = app.find('.account-detail-section')[0] + const detail2 = (await findAsync(app, '.account-detail-section'))[0] assert.ok(detail2, 'Account detail section loaded again.') - await timeout() - // open account settings dropdown - const qrButton = app.find('.fa.fa-ellipsis-h')[0] + const qrButton = (await findAsync(app, '.fa.fa-ellipsis-h'))[0] qrButton.click() - await timeout(1000) - // qr code item - const qrButton2 = app.find('.dropdown-menu-item')[1] + const qrButton2 = (await findAsync(app, '.dropdown-menu-item'))[1] qrButton2.click() - await timeout(1000) - - const qrHeader = app.find('.qr-header')[0] - const qrContainer = app.find('#qr-container')[0] + const qrHeader = (await findAsync(app, '.qr-header'))[0] + const qrContainer = (await findAsync(app, '#qr-container'))[0] assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.') assert.ok(qrContainer, 'QR Container found') - await timeout() - - const networkMenu = app.find('.network-indicator')[0] + const networkMenu = (await findAsync(app, '.network-indicator'))[0] networkMenu.click() - await timeout() - - const networkMenu2 = app.find('.network-indicator')[0] + const networkMenu2 = (await findAsync(app, '.network-indicator'))[0] const children2 = networkMenu2.children children2.length[3] assert.ok(children2, 'All network options present') } - -function timeout (time) { - return new Promise((resolve, reject) => { - setTimeout(resolve, time || 1500) - }) -} \ No newline at end of file diff --git a/test/integration/lib/send-new-ui.js b/test/integration/lib/send-new-ui.js index 3456f2367..07be63a36 100644 --- a/test/integration/lib/send-new-ui.js +++ b/test/integration/lib/send-new-ui.js @@ -1,4 +1,9 @@ const reactTriggerChange = require('react-trigger-change') +const { + timeout, + queryAsync, + findAsync, +} = require('../../lib/util') const PASSWORD = 'password123' @@ -18,83 +23,67 @@ global.ethQuery = { async function runSendFlowTest(assert, done) { console.log('*** start runSendFlowTest') - const selectState = $('select') + const selectState = await queryAsync($, 'select') selectState.val('send new ui') reactTriggerChange(selectState[0]) - await timeout(2000) - - const sendScreenButton = $('button.btn-clear.hero-balance-button') + const sendScreenButton = await queryAsync($, 'button.btn-clear.hero-balance-button') assert.ok(sendScreenButton[1], 'send screen button present') sendScreenButton[1].click() - await timeout(1000) - - const sendTitle = $('.page-container__title') + const sendTitle = await queryAsync($, '.page-container__title') assert.equal(sendTitle[0].textContent, 'Send ETH', 'Send screen title is correct') - const sendCopy = $('.page-container__subtitle') + const sendCopy = await queryAsync($, '.page-container__subtitle') assert.equal(sendCopy[0].textContent, 'Only send ETH to an Ethereum address.', 'Send screen has copy') - const sendFromField = $('.send-v2__form-field') + const sendFromField = await queryAsync($, '.send-v2__form-field') assert.ok(sendFromField[0], 'send screen has a from field') - let sendFromFieldItemAddress = $('.account-list-item__account-name') + let sendFromFieldItemAddress = await queryAsync($, '.account-list-item__account-name') assert.equal(sendFromFieldItemAddress[0].textContent, 'Send Account 4', 'send from field shows correct account name') - const sendFromFieldItem = $('.account-list-item') - sendFromFieldItem[0].click() - await timeout() + const sendFromFieldItem = await queryAsync($, '.account-list-item') + sendFromFieldItem[0].click() - const sendFromDropdownList = $('.send-v2__from-dropdown__list') + const sendFromDropdownList = await queryAsync($, '.send-v2__from-dropdown__list') assert.equal(sendFromDropdownList.children().length, 4, 'send from dropdown shows all accounts') console.log(`!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sendFromDropdownList.children()[1]`, sendFromDropdownList.children()[1]); sendFromDropdownList.children()[1].click() - await timeout() - - sendFromFieldItemAddress = $('.account-list-item__account-name') + sendFromFieldItemAddress = await queryAsync($, '.account-list-item__account-name') console.log(`!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sendFromFieldItemAddress[0]`, sendFromFieldItemAddress[0]); assert.equal(sendFromFieldItemAddress[0].textContent, 'Send Account 2', 'send from field dropdown changes account name') - let sendToFieldInput = $('.send-v2__to-autocomplete__input') + let sendToFieldInput = await queryAsync($, '.send-v2__to-autocomplete__input') sendToFieldInput[0].focus() - await timeout() - - const sendToDropdownList = $('.send-v2__from-dropdown__list') + const sendToDropdownList = await queryAsync($, '.send-v2__from-dropdown__list') assert.equal(sendToDropdownList.children().length, 5, 'send to dropdown shows all accounts and address book accounts') sendToDropdownList.children()[2].click() - await timeout() - const sendToAccountAddress = sendToFieldInput.val() assert.equal(sendToAccountAddress, '0x2f8d4a878cfa04a6e60d46362f5644deab66572d', 'send to dropdown selects the correct address') - const sendAmountField = $('.send-v2__form-row:eq(2)') + const sendAmountField = await queryAsync($, '.send-v2__form-row:eq(2)') sendAmountField.find('.currency-display')[0].click() - await timeout() - - const sendAmountFieldInput = sendAmountField.find('input:text') + const sendAmountFieldInput = await findAsync(sendAmountField, 'input:text') sendAmountFieldInput.val('5.1') reactTriggerChange(sendAmountField.find('input')[0]) - await timeout() - - let errorMessage = $('.send-v2__error') + let errorMessage = await queryAsync($, '.send-v2__error') assert.equal(errorMessage[0].textContent, 'Insufficient funds.', 'send should render an insufficient fund error message') sendAmountFieldInput.val('2.0') reactTriggerChange(sendAmountFieldInput[0]) - await timeout() errorMessage = $('.send-v2__error') assert.equal(errorMessage.length, 0, 'send should stop rendering amount error message after amount is corrected') - const sendGasField = $('.send-v2__gas-fee-display') + const sendGasField = await queryAsync($, '.send-v2__gas-fee-display') assert.equal( sendGasField.find('.currency-display__input-wrapper > input').val(), '0.000198', @@ -106,120 +95,86 @@ async function runSendFlowTest(assert, done) { 'send gas field should show estimated gas total converted to USD' ) - const sendGasOpenCustomizeModalButton = $('.send-v2__sliders-icon-container' - ) + const sendGasOpenCustomizeModalButton = await queryAsync($, '.send-v2__sliders-icon-container') sendGasOpenCustomizeModalButton[0].click() - await timeout(1000) - - const customizeGasModal = $('.send-v2__customize-gas') + const customizeGasModal = await queryAsync($, '.send-v2__customize-gas') assert.ok(customizeGasModal[0], 'should render the customize gas modal') - const customizeGasPriceInput = $('.send-v2__gas-modal-card').first().find('input') + const customizeGasPriceInput = (await queryAsync($, '.send-v2__gas-modal-card')).first().find('input') customizeGasPriceInput.val(50) reactTriggerChange(customizeGasPriceInput[0]) - const customizeGasLimitInput = $('.send-v2__gas-modal-card').last().find('input') + const customizeGasLimitInput = (await queryAsync($, '.send-v2__gas-modal-card')).last().find('input') customizeGasLimitInput.val(60000) reactTriggerChange(customizeGasLimitInput[0]) - await timeout() - - const customizeGasSaveButton = $('.send-v2__customize-gas__save') + const customizeGasSaveButton = await queryAsync($, '.send-v2__customize-gas__save') customizeGasSaveButton[0].click() - await timeout() - assert.equal( - sendGasField.find('.currency-display__input-wrapper > input').val(), + (await findAsync(sendGasField, '.currency-display__input-wrapper > input')).val(), '0.003', 'send gas field should show customized gas total' ) assert.equal( - sendGasField.find('.currency-display__converted-value')[0].textContent, + (await findAsync(sendGasField, '.currency-display__converted-value'))[0].textContent, '3.60 USD', 'send gas field should show customized gas total converted to USD' ) - const sendButton = $('button.btn-clear.page-container__footer-button') + const sendButton = await queryAsync($, 'button.btn-clear.page-container__footer-button') assert.equal(sendButton[0].textContent, 'Next', 'next button rendered') sendButton[0].click() - - await timeout(2000) + await timeout() selectState.val('send edit') reactTriggerChange(selectState[0]) - await timeout(2000) - - const confirmFromName = $('.confirm-screen-account-name').first() + const confirmFromName = (await queryAsync($, '.confirm-screen-account-name')).first() assert.equal(confirmFromName[0].textContent, 'Send Account 2', 'confirm screen should show correct from name') - const confirmToName = $('.confirm-screen-account-name').last() + const confirmToName = (await queryAsync($, '.confirm-screen-account-name')).last() assert.equal(confirmToName[0].textContent, 'Send Account 3', 'confirm screen should show correct to name') - const confirmScreenRows = $('.confirm-screen-rows') + const confirmScreenRows = await queryAsync($, '.confirm-screen-rows') const confirmScreenGas = confirmScreenRows.find('.confirm-screen-row-info')[2] assert.equal(confirmScreenGas.textContent, '3.6 USD', 'confirm screen should show correct gas') const confirmScreenTotal = confirmScreenRows.find('.confirm-screen-row-info')[3] assert.equal(confirmScreenTotal.textContent, '2405.36 USD', 'confirm screen should show correct total') - const confirmScreenBackButton = $('.confirm-screen-back-button') + const confirmScreenBackButton = await queryAsync($, '.confirm-screen-back-button') confirmScreenBackButton[0].click() - await timeout(1000) - - const sendFromFieldItemInEdit = $('.account-list-item') + const sendFromFieldItemInEdit = await queryAsync($, '.account-list-item') sendFromFieldItemInEdit[0].click() - await timeout() - - const sendFromDropdownListInEdit = $('.send-v2__from-dropdown__list') + const sendFromDropdownListInEdit = await queryAsync($, '.send-v2__from-dropdown__list') sendFromDropdownListInEdit.children()[2].click() - await timeout() - - const sendToFieldInputInEdit = $('.send-v2__to-autocomplete__input') + const sendToFieldInputInEdit = await queryAsync($, '.send-v2__to-autocomplete__input') sendToFieldInputInEdit[0].focus() sendToFieldInputInEdit.val('0xd85a4b6a394794842887b8284293d69163007bbb') - await timeout() - - const sendAmountFieldInEdit = $('.send-v2__form-row:eq(2)') + const sendAmountFieldInEdit = await queryAsync($, '.send-v2__form-row:eq(2)') sendAmountFieldInEdit.find('.currency-display')[0].click() - await timeout() - const sendAmountFieldInputInEdit = sendAmountFieldInEdit.find('input:text') sendAmountFieldInputInEdit.val('1.0') reactTriggerChange(sendAmountFieldInputInEdit[0]) - await timeout() - - const sendButtonInEdit = $('.btn-clear.page-container__footer-button') + const sendButtonInEdit = await queryAsync($, '.btn-clear.page-container__footer-button') assert.equal(sendButtonInEdit[0].textContent, 'Next', 'next button in edit rendered') sendButtonInEdit[0].click() - await timeout() - // TODO: Need a way to mock background so that we can test correct transition from editing to confirm selectState.val('confirm new ui') reactTriggerChange(selectState[0]) - - await timeout(2000) - const confirmScreenConfirmButton = $('.confirm-screen-confirm-button') + const confirmScreenConfirmButton = await queryAsync($, '.confirm-screen-confirm-button') console.log(`+++++++++++++++++++++++++++++++= confirmScreenConfirmButton[0]`, confirmScreenConfirmButton[0]); confirmScreenConfirmButton[0].click() - await timeout(2000) - - const txView = $('.tx-view') + const txView = await queryAsync($, '.tx-view') console.log(`++++++++++++++++++++++++++++++++ txView[0]`, txView[0]); assert.ok(txView[0], 'Should return to the account details screen after confirming') } - -function timeout (time) { - return new Promise((resolve, reject) => { - setTimeout(resolve, time || 1500) - }) -} \ No newline at end of file diff --git a/test/lib/util.js b/test/lib/util.js new file mode 100644 index 000000000..626280745 --- /dev/null +++ b/test/lib/util.js @@ -0,0 +1,53 @@ +module.exports = { + timeout, + queryAsync, + findAsync, + pollUntilTruthy, +} + +function timeout (time) { + return new Promise((resolve, reject) => { + setTimeout(resolve, time || 1500) + }) +} + +async function findAsync(container, selector, opts) { + try { + return await pollUntilTruthy(() => { + const result = container.find(selector) + if (result.length > 0) return result + }, opts) + } catch (err) { + throw new Error(`Failed to find element within interval: "${selector}"`) + } +} + +async function queryAsync(jQuery, selector, opts) { + try { + return await pollUntilTruthy(() => { + const result = jQuery(selector) + if (result.length > 0) return result + }, opts) + } catch (err) { + throw new Error(`Failed to find element within interval: "${selector}"`) + } +} + +async function pollUntilTruthy(fn, opts = {}){ + const pollingInterval = opts.pollingInterval || 100 + const timeoutInterval = opts.timeoutInterval || 5000 + const start = Date.now() + let result + while (!result) { + // check if timedout + const now = Date.now() + if ((now - start) > timeoutInterval) { + throw new Error(`pollUntilTruthy - failed to return truthy within interval`) + } + // check for result + result = fn() + // run again after timeout + await timeout(pollingInterval, timeoutInterval) + } + return result +} -- cgit v1.2.3 From 07fa26d1f094a7a405107c5f31674e65c94cea8d Mon Sep 17 00:00:00 2001 From: kumavis Date: Sun, 11 Mar 2018 18:52:27 -0700 Subject: test - add comment about test behavior oddity --- test/integration/index.js | 2 +- test/integration/lib/send-new-ui.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/integration/index.js b/test/integration/index.js index 144303dbb..b266ddf37 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -23,4 +23,4 @@ pump( console.log(`Integration test build completed: "${bundlePath}"`) process.exit(0) } -) \ No newline at end of file +) diff --git a/test/integration/lib/send-new-ui.js b/test/integration/lib/send-new-ui.js index 07be63a36..faab10fdf 100644 --- a/test/integration/lib/send-new-ui.js +++ b/test/integration/lib/send-new-ui.js @@ -43,17 +43,15 @@ async function runSendFlowTest(assert, done) { let sendFromFieldItemAddress = await queryAsync($, '.account-list-item__account-name') assert.equal(sendFromFieldItemAddress[0].textContent, 'Send Account 4', 'send from field shows correct account name') - await timeout() const sendFromFieldItem = await queryAsync($, '.account-list-item') sendFromFieldItem[0].click() + // this seems to fail if the firefox window is not in focus... const sendFromDropdownList = await queryAsync($, '.send-v2__from-dropdown__list') assert.equal(sendFromDropdownList.children().length, 4, 'send from dropdown shows all accounts') - console.log(`!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sendFromDropdownList.children()[1]`, sendFromDropdownList.children()[1]); sendFromDropdownList.children()[1].click() sendFromFieldItemAddress = await queryAsync($, '.account-list-item__account-name') - console.log(`!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sendFromFieldItemAddress[0]`, sendFromFieldItemAddress[0]); assert.equal(sendFromFieldItemAddress[0].textContent, 'Send Account 2', 'send from field dropdown changes account name') let sendToFieldInput = await queryAsync($, '.send-v2__to-autocomplete__input') -- cgit v1.2.3 From 3537c391db30bdec1d3fabb361dffc2e4a3931da Mon Sep 17 00:00:00 2001 From: kumavis Date: Sun, 11 Mar 2018 19:29:35 -0700 Subject: test - use new async selectors for faster testing --- test/integration/lib/confirm-sig-requests.js | 44 +++++-------- test/integration/lib/mascara-first-time.js | 94 ++++++++++------------------ 2 files changed, 49 insertions(+), 89 deletions(-) (limited to 'test') diff --git a/test/integration/lib/confirm-sig-requests.js b/test/integration/lib/confirm-sig-requests.js index e49424c37..9737a2283 100644 --- a/test/integration/lib/confirm-sig-requests.js +++ b/test/integration/lib/confirm-sig-requests.js @@ -1,5 +1,9 @@ const reactTriggerChange = require('react-trigger-change') - +const { + timeout, + queryAsync, + findAsync, +} = require('../../lib/util') const PASSWORD = 'password123' QUnit.module('confirm sig requests') @@ -13,55 +17,41 @@ QUnit.test('successful confirmation of sig requests', (assert) => { }) async function runConfirmSigRequestsTest(assert, done) { - let selectState = $('select') + let selectState = await queryAsync($, 'select') selectState.val('confirm sig requests') reactTriggerChange(selectState[0]) - await timeout(2000) - - let confirmSigHeadline = $('.request-signature__headline') + let confirmSigHeadline = await queryAsync($, '.request-signature__headline') assert.equal(confirmSigHeadline[0].textContent, 'Your signature is being requested') - let confirmSigRowValue = $('.request-signature__row-value') + let confirmSigRowValue = await queryAsync($, '.request-signature__row-value') assert.ok(confirmSigRowValue[0].textContent.match(/^\#\sTerms\sof\sUse/)) - let confirmSigSignButton = $('.request-signature__footer__sign-button') + let confirmSigSignButton = await queryAsync($, '.request-signature__footer__sign-button') confirmSigSignButton[0].click() - await timeout(2000) - - confirmSigHeadline = $('.request-signature__headline') + confirmSigHeadline = await queryAsync($, '.request-signature__headline') assert.equal(confirmSigHeadline[0].textContent, 'Your signature is being requested') - let confirmSigMessage = $('.request-signature__notice') + let confirmSigMessage = await queryAsync($, '.request-signature__notice') assert.ok(confirmSigMessage[0].textContent.match(/^Signing\sthis\smessage/)) - confirmSigRowValue = $('.request-signature__row-value') + confirmSigRowValue = await queryAsync($, '.request-signature__row-value') assert.equal(confirmSigRowValue[0].textContent, '0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0') - confirmSigSignButton = $('.request-signature__footer__sign-button') + confirmSigSignButton = await queryAsync($, '.request-signature__footer__sign-button') confirmSigSignButton[0].click() - await timeout(2000) - - confirmSigHeadline = $('.request-signature__headline') + confirmSigHeadline = await queryAsync($, '.request-signature__headline') assert.equal(confirmSigHeadline[0].textContent, 'Your signature is being requested') - confirmSigRowValue = $('.request-signature__row-value') + confirmSigRowValue = await queryAsync($, '.request-signature__row-value') assert.equal(confirmSigRowValue[0].textContent, 'Hi, Alice!') assert.equal(confirmSigRowValue[1].textContent, '1337') - confirmSigSignButton = $('.request-signature__footer__sign-button') + confirmSigSignButton = await queryAsync($, '.request-signature__footer__sign-button') confirmSigSignButton[0].click() - await timeout(2000) - - const txView = $('.tx-view') + const txView = await queryAsync($, '.tx-view') assert.ok(txView[0], 'Should return to the account details screen after confirming') } - -function timeout (time) { - return new Promise((resolve, reject) => { - setTimeout(resolve, time || 1500) - }) -} \ No newline at end of file diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index 515c7f383..d1afe12a0 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -1,119 +1,95 @@ const PASSWORD = 'password123' const reactTriggerChange = require('react-trigger-change') +const { + timeout, + findAsync, + queryAsync, +} = require('../../lib/util') async function runFirstTimeUsageTest (assert, done) { await timeout(4000) - const app = $('#app-content') + const app = await queryAsync($, '#app-content') await skipNotices(app) - await timeout() - // Scroll through terms - const title = app.find('.create-password__title').text() + const title = await findAsync(app, '.create-password__title').text() assert.equal(title, 'Create Password', 'create password screen') // enter password - const pwBox = app.find('.first-time-flow__input')[0] - const confBox = app.find('.first-time-flow__input')[1] + const pwBox = (await findAsync(app, '.first-time-flow__input'))[0] + const confBox = (await findAsync(app, '.first-time-flow__input'))[1] pwBox.value = PASSWORD confBox.value = PASSWORD reactTriggerChange(pwBox) reactTriggerChange(confBox) - - await timeout() - // Create Password - const createButton = app.find('button.first-time-flow__button')[0] + const createButton = (await findAsync(app, 'button.first-time-flow__button'))[0] createButton.click() - await timeout(3000) - - const created = app.find('.unique-image__title')[0] + const created = (await findAsync(app, '.unique-image__title'))[0] assert.equal(created.textContent, 'Your unique account image', 'unique image screen') // Agree button - let button = app.find('button')[0] + let button = (await findAsync(app, 'button'))[0] assert.ok(button, 'button present') button.click() - await timeout(1000) - await skipNotices(app) // secret backup phrase - const seedTitle = app.find('.backup-phrase__title')[0] + const seedTitle = (await findAsync(app, '.backup-phrase__title'))[0] assert.equal(seedTitle.textContent, 'Secret Backup Phrase', 'seed phrase screen') - app.find('.backup-phrase__reveal-button').click() - - await timeout(1000) - const seedPhrase = app.find('.backup-phrase__secret-words').text().split(' ') - app.find('.first-time-flow__button').click() + ;(await findAsync(app, '.backup-phrase__reveal-button')).click() + const seedPhrase = (await findAsync(app, '.backup-phrase__secret-words')).text().split(' ') + ;(await findAsync(app, '.first-time-flow__button')).click() + await timeout() const selectPhrase = text => { const option = $('.backup-phrase__confirm-seed-option') .filter((i, d) => d.textContent === text)[0] - $(option).click() } - await timeout(1000) - seedPhrase.forEach(sp => selectPhrase(sp)) - app.find('.first-time-flow__button').click() - await timeout(1000) + ;(await findAsync(app, '.first-time-flow__button')).click() // Deposit Ether Screen - const buyEthTitle = app.find('.buy-ether__title')[0] + const buyEthTitle = (await findAsync(app, '.buy-ether__title'))[0] assert.equal(buyEthTitle.textContent, 'Deposit Ether', 'deposit ether screen') - app.find('.buy-ether__do-it-later').click() - await timeout(1000) + ;(await findAsync(app, '.buy-ether__do-it-later')).click() - const menu = app.find('.account-menu__icon')[0] + const menu = (await findAsync(app, '.account-menu__icon'))[0] menu.click() - await timeout() - - const lock = app.find('.account-menu__logout-button')[0] + const lock = (await findAsync(app, '.account-menu__logout-button'))[0] assert.ok(lock, 'Lock menu item found') lock.click() - await timeout(1000) - - const pwBox2 = app.find('#password-box')[0] + const pwBox2 = (await findAsync(app, '#password-box'))[0] pwBox2.value = PASSWORD - const createButton2 = app.find('button.primary')[0] + const createButton2 = (await findAsync(app, 'button.primary'))[0] createButton2.click() - await timeout(1000) - - const detail2 = app.find('.wallet-view')[0] + const detail2 = (await findAsync(app, '.wallet-view'))[0] assert.ok(detail2, 'Account detail section loaded again.') - await timeout() - // open account settings dropdown - const qrButton = app.find('.wallet-view__details-button')[0] + const qrButton = (await findAsync(app, '.wallet-view__details-button'))[0] qrButton.click() - await timeout(1000) - - const qrHeader = app.find('.editable-label__value')[0] - const qrContainer = app.find('.qr-wrapper')[0] + const qrHeader = (await findAsync(app, '.editable-label__value'))[0] + const qrContainer = (await findAsync(app, '.qr-wrapper'))[0] assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.') assert.ok(qrContainer, 'QR Container found') - await timeout() - - const networkMenu = app.find('.network-component')[0] + const networkMenu = (await findAsync(app, '.network-component'))[0] networkMenu.click() - await timeout() - - const networkMenu2 = app.find('.network-indicator')[0] + const networkMenu2 = (await findAsync(app, '.network-indicator'))[0] const children2 = networkMenu2.children children2.length[3] assert.ok(children2, 'All network options present') @@ -121,18 +97,12 @@ async function runFirstTimeUsageTest (assert, done) { module.exports = runFirstTimeUsageTest -function timeout (time) { - return new Promise((resolve, reject) => { - setTimeout(resolve, time || 1500) - }) -} - async function skipNotices (app) { while (true) { - const button = app.find('button') + const button = await findAsync(app, 'button') if (button && button.html() === 'Accept') { // still notices to accept - const termsPage = app.find('.markdown')[0] + const termsPage = (await findAsync(app, '.markdown'))[0] if (!termsPage) { break } -- cgit v1.2.3 From 4bc69f72c3033cc9ea3e732f48da22d15c41a972 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sun, 11 Mar 2018 21:39:46 -0700 Subject: test - mascara - fix async wrap --- test/integration/lib/mascara-first-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/lib/mascara-first-time.js b/test/integration/lib/mascara-first-time.js index d1afe12a0..bcbc94ff6 100644 --- a/test/integration/lib/mascara-first-time.js +++ b/test/integration/lib/mascara-first-time.js @@ -14,7 +14,7 @@ async function runFirstTimeUsageTest (assert, done) { await skipNotices(app) // Scroll through terms - const title = await findAsync(app, '.create-password__title').text() + const title = (await findAsync(app, '.create-password__title')).text() assert.equal(title, 'Create Password', 'create password screen') // enter password -- cgit v1.2.3