6 acc "github.com/vapor/account"
7 "github.com/vapor/blockchain/signers"
8 "github.com/vapor/consensus"
9 "github.com/vapor/crypto/ed25519/chainkd"
10 "github.com/vapor/testutil"
14 //chainTxUtxoNum maximum utxo quantity in a tx
16 //chainTxMergeGas chain tx gas
17 chainTxMergeGas = uint64(10000000)
20 func TestBuildBtmTxChain(t *testing.T) {
22 m := mockAccountManager(t)
30 inputUtxo: []uint64{5},
31 wantInput: [][]uint64{},
32 wantOutput: [][]uint64{},
33 wantUtxo: 5 * chainTxMergeGas,
36 inputUtxo: []uint64{5, 4},
37 wantInput: [][]uint64{
40 wantOutput: [][]uint64{
43 wantUtxo: 8 * chainTxMergeGas,
46 inputUtxo: []uint64{5, 4, 1, 1},
47 wantInput: [][]uint64{
51 wantOutput: [][]uint64{
55 wantUtxo: 10 * chainTxMergeGas,
58 inputUtxo: []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24},
59 wantInput: [][]uint64{
60 []uint64{22, 123, 53, 234, 23},
61 []uint64{4, 2423, 24, 23, 43},
62 []uint64{34, 234, 234, 24, 454},
64 []uint64{234, 24, 197},
65 []uint64{260, 2469, 310},
68 wantOutput: [][]uint64{
77 wantUtxo: 3494 * chainTxMergeGas,
81 acct, err := m.Manager.Create([]chainkd.XPub{testutil.TestXPub}, 1, "testAccount", signers.BIP0044)
86 acp, err := m.Manager.CreateAddress(acct.ID, false)
91 for caseIndex, c := range cases {
92 utxos := []*acc.UTXO{}
93 for _, amount := range c.inputUtxo {
94 utxos = append(utxos, &acc.UTXO{
95 Amount: amount * chainTxMergeGas,
96 AssetID: *consensus.BTMAssetID,
98 ControlProgram: acp.ControlProgram,
102 tpls, gotUtxo, err := m.Manager.BuildBtmTxChain(utxos, acct.Signer)
107 for i, tpl := range tpls {
108 gotInput := []uint64{}
109 for _, input := range tpl.Transaction.Inputs {
110 gotInput = append(gotInput, input.Amount()/chainTxMergeGas)
113 gotOutput := []uint64{}
114 for _, output := range tpl.Transaction.Outputs {
115 gotOutput = append(gotOutput, output.AssetAmount().Amount/chainTxMergeGas)
118 if !testutil.DeepEqual(c.wantInput[i], gotInput) {
119 t.Errorf("case %d tx %d input got %d want %d", caseIndex, i, gotInput, c.wantInput[i])
121 if !testutil.DeepEqual(c.wantOutput[i], gotOutput) {
122 t.Errorf("case %d tx %d output got %d want %d", caseIndex, i, gotOutput, c.wantOutput[i])
126 if c.wantUtxo != gotUtxo.Amount {
127 t.Errorf("case %d got utxo=%d want utxo=%d", caseIndex, gotUtxo.Amount, c.wantUtxo)