aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/transaction-action/tests/transaction-action.component.test.js
blob: b22a9db3925953f8628c1e6d84d78b0885de4ec2 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import React from 'react'
import assert from 'assert'
import { shallow } from 'enzyme'
import sinon from 'sinon'
import TransactionAction from '../transaction-action.component'

describe('TransactionAction Component', () => {
  const t = key => key


  describe('Outgoing transaction', () => {
    beforeEach(() => {
      global.eth = {
        getCode: sinon.stub().callsFake(address => {
          const code = address === 'approveAddress' ? 'contract' : '0x'
          return Promise.resolve(code)
        }),
      }
    })

    it('should render -- when methodData is still fetching', () => {
      const methodData = { data: {}, done: false, error: null }
      const transaction = {
        id: 1,
        status: 'confirmed',
        submittedTime: 1534045442919,
        time: 1534045440641,
        txParams: {
          from: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
          gas: '0x5208',
          gasPrice: '0x3b9aca00',
          nonce: '0x96',
          to: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
          value: '0x2386f26fc10000',
        },
      }

      const wrapper = shallow(<TransactionAction
        methodData={methodData}
        transaction={transaction}
        className="transaction-action"
      />, { context: { t }})

      assert.equal(wrapper.find('.transaction-action').length, 1)
      assert.equal(wrapper.text(), '--')
    })

    it('should render Sent Ether', () => {
      const methodData = { data: {}, done: true, error: null }
      const transaction = {
        id: 1,
        status: 'confirmed',
        submittedTime: 1534045442919,
        time: 1534045440641,
        txParams: {
          from: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
          gas: '0x5208',
          gasPrice: '0x3b9aca00',
          nonce: '0x96',
          to: 'sentEtherAddress',
          value: '0x2386f26fc10000',
        },
      }

      const wrapper = shallow(<TransactionAction
        methodData={methodData}
        transaction={transaction}
        className="transaction-action"
      />, { context: { t }})

      assert.equal(wrapper.find('.transaction-action').length, 1)
      wrapper.setState({ transactionAction: 'sentEther' })
      assert.equal(wrapper.text(), 'sentEther')
    })

    it('should render Approved', async () => {
      const methodData = {
        data: {
          name: 'Approve',
          params: [
            { type: 'address' },
            { type: 'uint256' },
          ],
        },
        done: true,
        error: null,
      }
      const transaction = {
        id: 1,
        status: 'confirmed',
        submittedTime: 1534045442919,
        time: 1534045440641,
        txParams: {
          from: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
          gas: '0x5208',
          gasPrice: '0x3b9aca00',
          nonce: '0x96',
          to: 'approveAddress',
          value: '0x2386f26fc10000',
          data: '0x095ea7b300000000000000000000000050a9d56c2b8ba9a5c7f2c08c3d26e0499f23a7060000000000000000000000000000000000000000000000000000000000000003',
        },
      }

      const wrapper = shallow(
        <TransactionAction
          methodData={methodData}
          transaction={transaction}
          className="test-class"
        />,
        { context: { t } }
      )

      assert.ok(wrapper)
      assert.equal(wrapper.find('.test-class').length, 1)
      await wrapper.instance().getTransactionAction()
      assert.equal(wrapper.state('transactionAction'), 'approve')
    })

    it('should render Accept Fulfillment', async () => {
      const methodData = {
        data: {
          name: 'AcceptFulfillment',
          params: [
            { type: 'address' },
            { type: 'uint256' },
          ],
        },
        done: true,
        error: null,
      }
      const transaction = {
        id: 1,
        status: 'confirmed',
        submittedTime: 1534045442919,
        time: 1534045440641,
        txParams: {
          from: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
          gas: '0x5208',
          gasPrice: '0x3b9aca00',
          nonce: '0x96',
          to: 'approveAddress',
          value: '0x2386f26fc10000',
          data: '0x095ea7b300000000000000000000000050a9d56c2b8ba9a5c7f2c08c3d26e0499f23a7060000000000000000000000000000000000000000000000000000000000000003',
        },
      }

      const wrapper = shallow(
        <TransactionAction
          methodData={methodData}
          transaction={transaction}
          className="test-class"
        />,
        { context: { t }}
      )

      assert.ok(wrapper)
      assert.equal(wrapper.find('.test-class').length, 1)
      await wrapper.instance().getTransactionAction()
      assert.equal(wrapper.state('transactionAction'), ' Accept Fulfillment')
    })
  })
})