-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsend_test.go
67 lines (55 loc) · 1.77 KB
/
send_test.go
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
package tests
import (
"github.com/noah-blockchain/noah-go-node/core/code"
"github.com/noah-blockchain/noah-go-node/core/transaction"
"github.com/noah-blockchain/noah-go-node/core/types"
"github.com/noah-blockchain/noah-go-node/helpers"
"math/big"
"testing"
)
func TestSend(t *testing.T) {
address, pk := CreateAddress() // create account for test
state := DefaultAppState() // generate default state
// add address to genesis state
state.Accounts = append(state.Accounts, types.Account{
Address: address,
Balance: []types.Balance{
{
Coin: uint64(types.GetBaseCoinID()),
Value: helpers.BipToPip(big.NewInt(1)).String(),
},
},
Nonce: 0,
MultisigData: nil,
})
app := CreateApp(state) // create application
SendBeginBlock(app) // send BeginBlock
recipient, _ := CreateAddress() // generate recipient
value := big.NewInt(1)
tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{
Coin: types.GetBaseCoinID(),
To: recipient,
Value: value,
})
response := SendTx(app, SignTx(pk, tx)) // compose and send tx
// check that result is OK
if response.Code != code.OK {
t.Fatalf("Response code is not OK: %s, %d", response.Log, response.Code)
}
SendEndBlock(app) // send EndBlock
SendCommit(app) // send Commit
// check recipient's balance
{
balance := app.CurrentState().Accounts().GetBalance(recipient, types.GetBaseCoinID())
if balance.Cmp(value) != 0 {
t.Fatalf("Recipient balance is not correct. Expected %s, got %s", value, balance)
}
}
// check sender's balance
{
balance := app.CurrentState().Accounts().GetBalance(address, types.GetBaseCoinID())
if balance.String() != "989999999999999999" {
t.Fatalf("Recipient balance is not correct. Expected %s, got %s", "989999999999999999", balance)
}
}
}