MCPcopy
hub / github.com/canopy-network/canopy / TestApplyTransaction

Function TestApplyTransaction

fsm/transaction_test.go:12–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestApplyTransaction(t *testing.T) {
13 const amount = uint64(100)
14 // predefine a keygroup for signing the transaction
15 kg := newTestKeyGroup(t)
16 // predefine a send-transaction to insert into the block
17 sendTx, e := NewSendTransaction(kg.PrivateKey, newTestAddress(t), amount-1, 1, 1, 1, 1, "")
18 require.NoError(t, e)
19 tests := []struct {
20 name string
21 detail string
22 transaction lib.TransactionI
23 presetSender uint64
24 lastBlockTime time.Time
25 expected *lib.TxResult
26 error string
27 }{
28 {
29 name: "deduct fee fails",
30 detail: "failure on fee deduction",
31 lastBlockTime: time.Now(),
32 transaction: sendTx,
33 expected: &lib.TxResult{},
34 error: "insufficient funds",
35 },
36 {
37 name: "handle message fails",
38 detail: "failure on send",
39 lastBlockTime: time.Now(),
40 presetSender: amount - 1,
41 transaction: sendTx,
42 expected: &lib.TxResult{},
43 error: "insufficient funds",
44 },
45 {
46 name: "valid send tx",
47 detail: "happy path of the transaction being applied",
48 lastBlockTime: time.Now(),
49 presetSender: amount,
50 transaction: sendTx,
51 expected: &lib.TxResult{
52 Sender: newTestAddressBytes(t),
53 Recipient: newTestAddressBytes(t),
54 MessageType: "send",
55 Height: 2,
56 Index: 0,
57 Transaction: sendTx.(*lib.Transaction),
58 },
59 },
60 }
61 for _, test := range tests {
62 t.Run(test.name, func(t *testing.T) {
63 // create a state machine instance with default parameters
64 sm := newTestStateMachine(t)
65 // convenience variable for store
66 s := sm.store.(lib.StoreI)
67 // convert the transaction to bytes
68 tx, err := lib.Marshal(test.transaction)
69 require.NoError(t, err)

Callers

nothing calls this directly

Calls 14

MarshalFunction · 0.92
HashStringFunction · 0.92
HashFunction · 0.92
NewSendTransactionFunction · 0.85
newTestStateMachineFunction · 0.85
RunMethod · 0.80
UpdateParamMethod · 0.80
AccountAddMethod · 0.80
ApplyTransactionMethod · 0.80
EqualMethod · 0.80
newTestKeyGroupFunction · 0.70
newTestAddressFunction · 0.70

Tested by

no test coverage detected