forked from FactomProject/factom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_test.go
88 lines (75 loc) · 1.78 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2016 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package factom_test
import (
. "github.com/FactomProject/factom"
"testing"
"encoding/json"
"time"
)
func TestJSONTransactions(t *testing.T) {
tx1 := mkdummytx()
t.Log("Transaction:", tx1)
p, err := json.Marshal(tx1)
if err != nil {
t.Error(err)
}
t.Log("JSON transaction:", string(p))
tx2 := new(Transaction)
if err := json.Unmarshal(p, tx2); err != nil {
t.Error(err)
}
t.Log("Unmarshaled:", tx2)
}
func TestTransactions(t *testing.T) {
// start the test wallet
done, err := StartTestWallet()
if err != nil {
t.Error(err)
}
defer func() { done <- 1 }()
// make sure the wallet is empty
if txs, err := ListTransactionsTmp(); err != nil {
t.Error(err)
} else if len(txs) > 0 {
t.Error("Unexpected transactions returned from the wallet:", txs)
}
// create a new transaction
tx1, err := NewTransaction("tx1")
if err != nil {
t.Error(err)
}
if tx1 == nil {
t.Error("No transaction was returned")
}
if tx, err := GetTmpTransaction("tx1"); err != nil {
t.Error(err)
} else if tx == nil {
t.Error("Temporary transaction was not saved in the wallet")
}
// delete a transaction
if err := DeleteTransaction("tx1"); err != nil {
t.Error(err)
}
if txs, err := ListTransactionsTmp(); err != nil {
t.Error(err)
} else if len(txs) > 0 {
t.Error("Unexpected transactions returned from the wallet:", txs)
}
}
// helper functions for testing
func mkdummytx() *Transaction {
tx := &Transaction{
BlockHeight: 42,
Name: "dummy",
Timestamp: func() time.Time {
t, _ := time.Parse("2006-Jan-02 15:04", "1988-Jan-02 10:00")
return t
}(),
TotalInputs: 13,
TotalOutputs: 12,
TotalECOutputs: 1,
}
return tx
}