-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtx_test.go
More file actions
49 lines (38 loc) · 1.19 KB
/
Copy pathtx_test.go
File metadata and controls
49 lines (38 loc) · 1.19 KB
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
package gobc_test
import (
"testing"
gobc "github.com/RahilRehan/go-bc"
"github.com/stretchr/testify/require"
)
func TestTransactionCreation(t *testing.T) {
sender := gobc.NewWallet()
require.NotNil(t, sender)
}
func TestNegativeAmountTransaction(t *testing.T) {
sender := gobc.NewWallet()
recipient := gobc.NewWallet()
amount := int64(-20)
tx := gobc.NewTransaction(&sender, &recipient, amount)
require.Nil(t, tx)
}
func TestInSufficientBalanceTransaction(t *testing.T) {
sender := gobc.NewWallet()
recipient := gobc.NewWallet()
amount := int64(sender.Balance + 1)
tx := gobc.NewTransaction(&sender, &recipient, amount)
require.Nil(t, tx)
}
func TestTransactionBetweenTwoWallets(t *testing.T) {
sender := gobc.NewWallet()
recipient := gobc.NewWallet()
amount := int64(20)
tx := gobc.NewTransaction(&sender, &recipient, amount)
tx.Sign(&sender, &tx.Output)
require.NotNil(t, tx)
require.Equal(t, tx.Output[0].Address, sender.PublicKey)
require.Equal(t, tx.Output[0].Amount, sender.Balance-amount)
require.Equal(t, tx.Output[1].Address, recipient.PublicKey)
require.Equal(t, tx.Output[1].Amount, amount)
verified := tx.Verify(&sender, tx.Input.Signature)
require.True(t, verified)
}