aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/selectors/tests/custom-gas.test.js
blob: d53c1ec9886d34e2be7f27003c88c4ea88759ab4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import assert from 'assert'
import proxyquire from 'proxyquire'

const {
  getCustomGasErrors,
  getCustomGasLimit,
  getCustomGasPrice,
  getCustomGasTotal,
  getRenderableBasicEstimateData,
} = proxyquire('../custom-gas', {})

describe('custom-gas selectors', () => {

  describe('getCustomGasPrice()', () => {
    it('should return gas.customData.price', () => {
      const mockState = { gas: { customData: { price: 'mockPrice' } } }
      assert.equal(getCustomGasPrice(mockState), 'mockPrice')
    })
  })

  describe('getCustomGasLimit()', () => {
    it('should return gas.customData.limit', () => {
      const mockState = { gas: { customData: { limit: 'mockLimit' } } }
      assert.equal(getCustomGasLimit(mockState), 'mockLimit')
    })
  })

  describe('getCustomGasTotal()', () => {
    it('should return gas.customData.total', () => {
      const mockState = { gas: { customData: { total: 'mockTotal' } } }
      assert.equal(getCustomGasTotal(mockState), 'mockTotal')
    })
  })

  describe('getCustomGasErrors()', () => {
    it('should return gas.errors', () => {
      const mockState = { gas: { errors: 'mockErrors' } }
      assert.equal(getCustomGasErrors(mockState), 'mockErrors')
    })
  })

  describe('getRenderableBasicEstimateData()', () => {
    const tests = [
      {
        expectedResult: [
          {
            feeInPrimaryCurrency: '$0.05',
            feeInSecondaryCurrency: '0.00021 ETH',
            timeEstimate: '~7 sec',
            priceInHexWei: '0x2540be400',
          },
          {
            feeInPrimaryCurrency: '$0.03',
            feeInSecondaryCurrency: '0.000105 ETH',
            timeEstimate: '~46 sec',
            priceInHexWei: '0x12a05f200',
          },
          {
            feeInPrimaryCurrency: '$0.01',
            feeInSecondaryCurrency: '0.0000525 ETH',
            timeEstimate: '~1 min 33 sec',
            priceInHexWei: '0x9502f900',
          },
        ],
        mockState: {
          metamask: {
            conversionRate: 255.71,
            currentCurrency: 'usd',
            send: {
              gasLimit: '0x5208',
            },
          },
          gas: {
            basicEstimates: {
              blockTime: 14.16326530612245,
              safeLow: 25,
              safeLowWait: 6.6,
              average: 50,
              avgWait: 3.3,
              fast: 100,
              fastWait: 0.5,
            },
          },
        },
      },
      {
        expectedResult: [
          {
            feeInPrimaryCurrency: '$1.07',
            feeInSecondaryCurrency: '0.00042 ETH',
            timeEstimate: '~14 sec',
            priceInHexWei: '0x4a817c800',
          },
          {
            feeInPrimaryCurrency: '$0.54',
            feeInSecondaryCurrency: '0.00021 ETH',
            timeEstimate: '~1 min 33 sec',
            priceInHexWei: '0x2540be400',
          },
          {
            feeInPrimaryCurrency: '$0.27',
            feeInSecondaryCurrency: '0.000105 ETH',
            timeEstimate: '~3 min 7 sec',
            priceInHexWei: '0x12a05f200',
          },
        ],
        mockState: {
          metamask: {
            conversionRate: 2557.1,
            currentCurrency: 'usd',
            send: {
              gasLimit: '0x5208',
            },
          },
          gas: {
            basicEstimates: {
              blockTime: 14.16326530612245,
              safeLow: 50,
              safeLowWait: 13.2,
              average: 100,
              avgWait: 6.6,
              fast: 200,
              fastWait: 1.0,
            },
          },
        },
      },
    ]
    it('should return renderable data about basic estimates', () => {
      tests.forEach(test => {
        assert.deepEqual(
          getRenderableBasicEstimateData(test.mockState),
          test.expectedResult
        )
      })
    })

  })

})