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, 11, 16, 33, 59, 73, 89, 66},
59 wantInput: [][]uint64{
60 []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24, 11, 16, 33, 59, 73, 89},
63 wantOutput: [][]uint64{
67 wantUtxo: 3843 * chainTxMergeGas,
71 acct, err := m.Manager.Create([]chainkd.XPub{testutil.TestXPub}, 1, "testAccount", signers.BIP0044)
76 acp, err := m.Manager.CreateAddress(acct.ID, false)
81 for caseIndex, c := range cases {
82 utxos := []*acc.UTXO{}
83 for _, amount := range c.inputUtxo {
84 utxos = append(utxos, &acc.UTXO{
85 Amount: amount * chainTxMergeGas,
86 AssetID: *consensus.BTMAssetID,
88 ControlProgram: acp.ControlProgram,
92 tpls, gotUtxo, err := m.Manager.BuildBtmTxChain(utxos, acct.Signer)
97 for i, tpl := range tpls {
98 gotInput := []uint64{}
99 for _, input := range tpl.Transaction.Inputs {
100 gotInput = append(gotInput, input.Amount()/chainTxMergeGas)
103 gotOutput := []uint64{}
104 for _, output := range tpl.Transaction.Outputs {
105 gotOutput = append(gotOutput, output.AssetAmount().Amount/chainTxMergeGas)
108 if !testutil.DeepEqual(c.wantInput[i], gotInput) {
109 t.Errorf("case %d tx %d input got %d want %d", caseIndex, i, gotInput, c.wantInput[i])
111 if !testutil.DeepEqual(c.wantOutput[i], gotOutput) {
112 t.Errorf("case %d tx %d output got %d want %d", caseIndex, i, gotOutput, c.wantOutput[i])
116 if c.wantUtxo != gotUtxo.Amount {
117 t.Errorf("case %d got utxo=%d want utxo=%d", caseIndex, gotUtxo.Amount, c.wantUtxo)