This repository was archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtransactor_test.go
103 lines (85 loc) · 2.25 KB
/
transactor_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package transactor
import (
"context"
"math/big"
"testing"
"github.com/Dev43/arweave-go/tx"
"github.com/Dev43/arweave-go/utils"
"github.com/stretchr/testify/assert"
)
var ctx = context.TODO()
type mockCaller struct {
LastTx string
Reward string
Txn *tx.Transaction
}
func (m *mockCaller) TxAnchor(ctx context.Context) (string, error) {
return m.LastTx, nil
}
func (m *mockCaller) LastTransaction(ctx context.Context, address string) (string, error) {
return m.LastTx, nil
}
func (m *mockCaller) GetReward(ctx context.Context, data []byte) (string, error) {
return m.Reward, nil
}
func (m *mockCaller) Commit(ctx context.Context, data []byte) (string, error) {
return "TESTOK", nil
}
func (m *mockCaller) GetTransaction(ctx context.Context, txID string) (*tx.Transaction, error) {
return m.Txn, nil
}
type mockWallet struct {
Signature []byte
TestAddress string
TestPubKeyModulus *big.Int
}
func (w *mockWallet) Sign(msg []byte) ([]byte, error) {
return w.Signature, nil
}
func (w *mockWallet) Verify(msg []byte, sig []byte) error {
return nil
}
func (w *mockWallet) Address() string {
return w.TestAddress
}
func (w *mockWallet) PubKeyModulus() *big.Int {
return w.TestPubKeyModulus
}
func TestCreateTransaction(t *testing.T) {
cases := []struct {
caller *mockCaller
wallet *mockWallet
quantity string
target string
data []byte
tag []tx.Tag
}{
{
&mockCaller{
LastTx: "0xA",
Reward: "1000",
Txn: nil},
&mockWallet{
Signature: nil,
TestAddress: "0xB",
TestPubKeyModulus: big.NewInt(1),
},
"1",
"0xC",
[]byte("hello"),
make([]tx.Tag, 0),
},
}
for _, c := range cases {
tr := Transactor{Client: c.caller}
tx, err := tr.CreateTransaction(ctx, c.wallet, c.quantity, c.data, c.target)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, c.quantity, tx.Quantity(), "quantity field does not match")
assert.Equal(t, c.target, tx.Target(), "target field does not match")
assert.Equal(t, c.caller.LastTx, tx.LastTx(), "last tx field does not match")
assert.Equal(t, c.caller.Reward, tx.Reward(), "reward field does not match")
assert.Equal(t, utils.EncodeToBase64(c.wallet.PubKeyModulus().Bytes()), tx.Owner(), "owner field does not match")
}
}