aboutsummaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-02-16 08:09:16 +0800
committerDan Finlay <dan@danfinlay.com>2017-02-16 08:09:16 +0800
commit6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf (patch)
tree47906b974dee789ffd544b4c85da67e6f2323016 /test/lib
parent245e779f37763ce0633119c257877706d0bf3554 (diff)
parent943bcec0d702b2c70b323000ed25d3c425e2a44f (diff)
downloadtangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.gz
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.bz2
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.lz
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.xz
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.tar.zst
tangerine-wallet-browser-6d103dc1e7eeb9a1f55e4387fcc1fe194c7eb4cf.zip
Merge branch 'kumavis-patch-1' of github.com:MetaMask/metamask-plugin into kumavis-patch-1
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/example-code.json3
-rw-r--r--test/lib/migrations/004.json138
-rw-r--r--test/lib/mock-config-manager.js63
-rw-r--r--test/lib/mock-encryptor.js32
-rw-r--r--test/lib/mock-simple-keychain.js38
5 files changed, 219 insertions, 55 deletions
diff --git a/test/lib/example-code.json b/test/lib/example-code.json
new file mode 100644
index 000000000..b76d37a4c
--- /dev/null
+++ b/test/lib/example-code.json
@@ -0,0 +1,3 @@
+{
+ "delegateCallCode": "0x606060405260e060020a60003504637bd703e8811461003157806390b98a111461005c578063f8b2cb4f1461008e575b005b6100b4600435600073f28c53067227848f8145355c455da5cfdd20e3136396e4ee3d6100da84610095565b6100c660043560243533600160a060020a03166000908152602081905260408120548290101561011f57506000610189565b6100b46004355b600160a060020a0381166000908152602081905260409020545b919050565b60408051918252519081900360200190f35b604080519115158252519081900360200190f35b60026040518360e060020a02815260040180838152602001828152602001925050506020604051808303818660325a03f4156100025750506040515191506100af9050565b33600160a060020a0390811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9291505056"
+}
diff --git a/test/lib/migrations/004.json b/test/lib/migrations/004.json
new file mode 100644
index 000000000..0e2075c46
--- /dev/null
+++ b/test/lib/migrations/004.json
@@ -0,0 +1,138 @@
+{
+ "meta":{
+ "version":4
+ },
+ "data":{
+ "seedWords":null,
+ "fiatCurrency":"USD",
+ "isDisclaimerConfirmed":true,
+ "TOSHash":"a4f4e23f823a7ac51783e7ffba7914a911b09acdb97263296b7e14b527f80c5b",
+ "shapeShiftTxList":[
+ {
+ "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw",
+ "depositType": "BTC",
+ "key": "shapeshift",
+ "time": 1471564825772,
+ "response": {
+ "status": "complete",
+ "outgoingCoin": "100.00",
+ "incomingCoin": "1.000",
+ "transaction": "0x3701e0ac344a12a1fc5417cf251109a7c41f3edab922310202630d9c012414c8"
+ }
+ },
+ {
+ "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw",
+ "depositType": "BTC",
+ "key": "shapeshift",
+ "time": 1471566579224,
+ "response": {
+ "status": "no_deposits",
+ "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw"
+ }
+ },
+ {
+ "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw",
+ "depositType": "BTC",
+ "key": "shapeshift",
+ "time": 1471566565378,
+ "response": {
+ "status": "received",
+ "depositAddress": "1L8BJCR6KHkCiVceDqibt7zJscqPpH7pFw"
+ }
+ }
+ ],
+ "noticesList":[
+ {
+ "read":true,
+ "date":"Fri Dec 16 2016",
+ "title":"Ending Morden Support",
+ "body":"Due to [recent events](https://blog.ethereum.org/2016/11/20/from-morden-to-ropsten/), MetaMask is now deprecating support for the Morden Test Network.\n\nUsers will still be able to access Morden through a locally hosted node, but we will no longer be providing hosted access to this network through [Infura](http://infura.io/).\n\nPlease use the new Ropsten Network as your new default test network.\n\nYou can fund your Ropsten account using the buy button on your account page.\n\nBest wishes!\nThe MetaMask Team\n\n",
+ "id":0
+ }
+ ],
+ "conversionRate":12.66441492,
+ "conversionDate":1487184182,
+ "vault":"{\"data\":\"Z5UFCeI/Tg9F9No0dC7eIhe4evCG91m6qeXhGpSeX48HHCQ/BepyNONKrh05YjB9hXCAd3Jy93judD+pcXNy7WS9zLujjmMI6sI90ToSrzThnMrOE6ixcH7HGS+TCcqvwBhZEsAQqUcQeHhT9CcdCQAxkKwBk8CK8W290MVeZoQVGK88hB2R8kL3mo/uayS5AnHPwWOS0rocgSfd/ioiucClpw==\",\"iv\":\"AYufeEPwp9f2Rdrfq7yS8g==\",\"salt\":\"g7BQIEx8tosH3IxWhPnrgZFu1XRkQn1Pp7l1ehTQQCo=\"}",
+ "config":{
+ "provider":{
+ "type":"testnet"
+ },
+ "selectedAccount":"0x0beb674745816b125fbc07285d39fd373e64895c"
+ },
+ "walletNicknames":{
+ "0x0beb674745816b125fbc07285d39fd373e64895c":"Account 1",
+ "0x433eb37d2e4895815b90f555425dfa123ddaed40":"Account 2"
+ },
+ "transactions":[
+ {
+ "id":3922064325443430,
+ "time":1487184358262,
+ "status":"confirmed",
+ "gasMultiplier":1,
+ "metamaskNetworkId":"3",
+ "txParams":{
+ "from":"0x0beb674745816b125fbc07285d39fd373e64895c",
+ "to":"0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761",
+ "value":"0xde0b6b3a7640000",
+ "metamaskId":3922064325443430,
+ "metamaskNetworkId":"3",
+ "gas":"0x5209",
+ "gasPrice":"0x04a817c800",
+ "nonce":"0x0",
+ "gasLimit":"0x5209"
+ },
+ "gasLimitSpecified":false,
+ "estimatedGas":"0x5209",
+ "txFee":"17e0186e60800",
+ "txValue":"de0b6b3a7640000",
+ "maxCost":"de234b52e4a0800",
+ "hash":"0x0b36c5bb31528044e6a71e45a64e9872f5f365a14ac42ee1bea49e7766216c12"
+ },
+ {
+ "id":3922064325443431,
+ "time":1487184373172,
+ "status":"confirmed",
+ "gasMultiplier":1,
+ "metamaskNetworkId":"3",
+ "txParams":{
+ "from":"0x0beb674745816b125fbc07285d39fd373e64895c",
+ "to":"0x433eb37d2e4895815b90f555425dfa123ddaed40",
+ "value":"0xde0b6b3a7640000",
+ "metamaskId":3922064325443431,
+ "metamaskNetworkId":"3",
+ "gas":"0x5209",
+ "nonce":"0x01",
+ "gasPrice":"0x04a817c800",
+ "gasLimit":"0x5209"
+ },
+ "gasLimitSpecified":false,
+ "estimatedGas":"0x5209",
+ "txFee":"17e0186e60800",
+ "txValue":"de0b6b3a7640000",
+ "maxCost":"de234b52e4a0800",
+ "hash":"0x305548a8b8bb72de0ca8cf77df45e4fe2b29383e58c4da6b7eac7e9bd59e85e9"
+ },
+ {
+ "id":3922064325443432,
+ "time":1487184391226,
+ "status":"unapproved",
+ "gasMultiplier":1,
+ "metamaskNetworkId":"3",
+ "txParams":{
+ "from":"0x0beb674745816b125fbc07285d39fd373e64895c",
+ "to":"0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761",
+ "value":"0xde0b6b3a7640000",
+ "metamaskId":3922064325443432,
+ "metamaskNetworkId":"3",
+ "gas":"0x5209"
+ },
+ "gasLimitSpecified":false,
+ "estimatedGas":"0x5209",
+ "txFee":"17e0186e60800",
+ "txValue":"de0b6b3a7640000",
+ "maxCost":"de234b52e4a0800"
+ }
+ ],
+ "gasMultiplier":1
+ }
+}
diff --git a/test/lib/mock-config-manager.js b/test/lib/mock-config-manager.js
index fe841f455..72be86ed1 100644
--- a/test/lib/mock-config-manager.js
+++ b/test/lib/mock-config-manager.js
@@ -1,57 +1,10 @@
-var ConfigManager = require('../../app/scripts/lib/config-manager')
-const STORAGE_KEY = 'metamask-persistance-key'
-const extend = require('xtend')
+const ObservableStore = require('obs-store')
+const clone = require('clone')
+const ConfigManager = require('../../app/scripts/lib/config-manager')
+const firstTimeState = require('../../app/scripts/first-time-state')
+const STORAGE_KEY = 'metamask-config'
module.exports = function() {
- return new ConfigManager({ loadData, setData })
-}
-
-function loadData () {
- var oldData = getOldStyleData()
- var newData
- try {
- newData = JSON.parse(window.localStorage[STORAGE_KEY])
- } catch (e) {}
-
- var data = extend({
- meta: {
- version: 0,
- },
- data: {
- config: {
- provider: {
- type: 'testnet',
- },
- },
- },
- }, oldData || null, newData || null)
- return data
-}
-
-function getOldStyleData () {
- var config, wallet, seedWords
-
- var result = {
- meta: { version: 0 },
- data: {},
- }
-
- try {
- config = JSON.parse(window.localStorage['config'])
- result.data.config = config
- } catch (e) {}
- try {
- wallet = JSON.parse(window.localStorage['lightwallet'])
- result.data.wallet = wallet
- } catch (e) {}
- try {
- seedWords = window.localStorage['seedWords']
- result.data.seedWords = seedWords
- } catch (e) {}
-
- return result
-}
-
-function setData (data) {
- window.localStorage[STORAGE_KEY] = JSON.stringify(data)
-}
+ let store = new ObservableStore(clone(firstTimeState))
+ return new ConfigManager({ store })
+} \ No newline at end of file
diff --git a/test/lib/mock-encryptor.js b/test/lib/mock-encryptor.js
new file mode 100644
index 000000000..09bbf7ad5
--- /dev/null
+++ b/test/lib/mock-encryptor.js
@@ -0,0 +1,32 @@
+var mockHex = '0xabcdef0123456789'
+var mockKey = new Buffer(32)
+let cacheVal
+
+module.exports = {
+
+ encrypt(password, dataObj) {
+ cacheVal = dataObj
+ return Promise.resolve(mockHex)
+ },
+
+ decrypt(password, text) {
+ return Promise.resolve(cacheVal || {})
+ },
+
+ encryptWithKey(key, dataObj) {
+ return this.encrypt(key, dataObj)
+ },
+
+ decryptWithKey(key, text) {
+ return this.decrypt(key, text)
+ },
+
+ keyFromPassword(password) {
+ return Promise.resolve(mockKey)
+ },
+
+ generateSalt() {
+ return 'WHADDASALT!'
+ },
+
+}
diff --git a/test/lib/mock-simple-keychain.js b/test/lib/mock-simple-keychain.js
new file mode 100644
index 000000000..615b3e537
--- /dev/null
+++ b/test/lib/mock-simple-keychain.js
@@ -0,0 +1,38 @@
+var fakeWallet = {
+ privKey: '0x123456788890abcdef',
+ address: '0xfedcba0987654321',
+}
+const type = 'Simple Key Pair'
+
+module.exports = class MockSimpleKeychain {
+
+ static type() { return type }
+
+ constructor(opts) {
+ this.type = type
+ this.opts = opts || {}
+ this.wallets = []
+ }
+
+ serialize() {
+ return [ fakeWallet.privKey ]
+ }
+
+ deserialize(data) {
+ if (!Array.isArray(data)) {
+ throw new Error('Simple keychain deserialize requires a privKey array.')
+ }
+ this.wallets = [ fakeWallet ]
+ }
+
+ addAccounts(n = 1) {
+ for(var i = 0; i < n; i++) {
+ this.wallets.push(fakeWallet)
+ }
+ }
+
+ getAccounts() {
+ return this.wallets.map(w => w.address)
+ }
+
+}