(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func 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) |
nothing calls this directly
no test coverage detected