-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction_test.go
65 lines (50 loc) · 1.43 KB
/
transaction_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
package ncoin_wallet
import (
"testing"
)
func TestSignTransactionFull(t *testing.T) {
transaction := NewTransaction(12318464, 5468421, 25.6, 1.4)
err = transaction.Sign(privateKey)
if err != nil {
t.Errorf("Fail in sign transaction %s", err.Error())
}
err = transaction.Verify(publicKey)
if err != nil {
t.Errorf("Fail to verify transaction %s", err.Error())
}
}
func TestSignTransactionEmpty(t *testing.T) {
transaction := Transaction{}
err := transaction.Sign(privateKey)
if err != nil {
t.Errorf("Fail in sign transaction %s", err.Error())
}
err = transaction.Verify(publicKey)
if err != nil {
t.Errorf("Fail to verify transaction %s", err.Error())
}
}
func TestFailSignByChange(t *testing.T) {
transaction := NewTransaction(12318464, 5468421, 25.6, 1.4)
err := transaction.Sign(privateKey)
if err != nil {
t.Errorf("Fail in sign transaction %s", err.Error())
}
transaction.fee = 8.6
err = transaction.Verify(publicKey)
if err == nil {
t.Errorf("Should fail because fee atribute is change: %s", err.Error())
}
}
func TestFailSignByBadCredentials(t *testing.T) {
transaction := NewTransaction(12318464, 5468421, 25.6, 1.4)
err := transaction.Sign(privateKey)
if err != nil {
t.Errorf("Fail in sign transaction %s", err.Error())
}
_, publicKeyTest, _ := GenerateKeys()
err = transaction.Verify(publicKeyTest)
if err == nil {
t.Errorf("Should fail because the public key its another; %s", err.Error())
}
}