-
Notifications
You must be signed in to change notification settings - Fork 95
/
allotment_test.go
104 lines (96 loc) · 2.72 KB
/
allotment_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
104
package iotago_test
import (
"testing"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/tpkg"
"github.com/iotaledger/iota.go/v4/tpkg/frameworks"
)
func TestAllotmentDeSerialize(t *testing.T) {
type allotmentDeSerializeTest struct {
name string
source iotago.TxEssenceAllotments
seriErr error
deSeriErr error
}
accountID1 := iotago.MustAccountIDFromHexString("0x7238fbce2f6ae391bd4eb2ce1c51085e0945943bb1bb8e9133e29672c8ef2c74")
accountID2 := iotago.MustAccountIDFromHexString("0x98f3e0f153461a73f09b6f9eedf7acbd11447f86d6ad20817973a2e2c9240f32")
accountID3 := iotago.MustAccountIDFromHexString("0xf23ae970dc1359ff48f4169b7cec237873992dc30d9eeb6ccacdecc7679e4f69")
tests := []allotmentDeSerializeTest{
{
name: "ok - multiple unique allotments in order",
source: iotago.TxEssenceAllotments{
&iotago.Allotment{
AccountID: accountID1,
Mana: 5,
},
&iotago.Allotment{
AccountID: accountID2,
Mana: 4,
},
&iotago.Allotment{
AccountID: accountID3,
Mana: 6,
},
},
},
{
name: "err - account id in allotments not lexically ordered",
source: iotago.TxEssenceAllotments{
&iotago.Allotment{
AccountID: accountID2,
Mana: 500,
},
&iotago.Allotment{
AccountID: accountID1,
Mana: 800,
},
&iotago.Allotment{
AccountID: accountID3,
Mana: 800,
},
},
seriErr: iotago.ErrArrayValidationOrderViolatesLexicalOrder,
deSeriErr: iotago.ErrArrayValidationOrderViolatesLexicalOrder,
},
{
name: "err - account id in allotments not unique",
source: iotago.TxEssenceAllotments{
&iotago.Allotment{
AccountID: accountID1,
Mana: 500,
},
&iotago.Allotment{
AccountID: accountID1,
Mana: 800,
},
},
seriErr: iotago.ErrArrayValidationViolatesUniqueness,
deSeriErr: iotago.ErrArrayValidationViolatesUniqueness,
},
}
for _, test := range tests {
stx := tpkg.RandSignedTransactionWithTransaction(tpkg.ZeroCostTestAPI, &iotago.Transaction{
API: tpkg.ZeroCostTestAPI,
TransactionEssence: &iotago.TransactionEssence{
Allotments: test.source,
Capabilities: iotago.TransactionCapabilitiesBitMaskWithCapabilities(),
ContextInputs: iotago.TxEssenceContextInputs{},
NetworkID: tpkg.ZeroCostTestAPI.ProtocolParameters().NetworkID(),
Inputs: iotago.TxEssenceInputs{
tpkg.RandUTXOInput(),
},
},
Outputs: iotago.TxEssenceOutputs{
tpkg.RandBasicOutput(),
},
})
tst := &frameworks.DeSerializeTest{
Name: test.name,
Source: stx,
Target: &iotago.SignedTransaction{},
SeriErr: test.seriErr,
DeSeriErr: test.deSeriErr,
}
t.Run(tst.Name, tst.Run)
}
}