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
18 func TestBuildBtmTxChain(t *testing.T) {
20 m := mockAccountManager(t)
28 inputUtxo: []uint64{5},
29 wantInput: [][]uint64{},
30 wantOutput: [][]uint64{},
34 inputUtxo: []uint64{5, 4},
35 wantInput: [][]uint64{
38 wantOutput: [][]uint64{
44 inputUtxo: []uint64{5, 4, 1, 1},
45 wantInput: [][]uint64{
49 wantOutput: [][]uint64{
56 inputUtxo: []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24, 11, 16, 33, 59, 73, 89, 66},
57 wantInput: [][]uint64{
58 []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24, 11, 16, 33, 59, 73, 89},
61 wantOutput: [][]uint64{
69 acct, err := m.Manager.Create([]chainkd.XPub{testutil.TestXPub}, 1, "testAccount", signers.BIP0044)
74 acp, err := m.Manager.CreateAddress(acct.ID, false)
79 for caseIndex, c := range cases {
80 utxos := []*acc.UTXO{}
81 for _, amount := range c.inputUtxo {
82 utxos = append(utxos, &acc.UTXO{
84 AssetID: *consensus.BTMAssetID,
86 ControlProgram: acp.ControlProgram,
90 tpls, gotUtxo, err := m.Manager.BuildBtmTxChain(utxos, acct.Signer)
95 for i, tpl := range tpls {
96 gotInput := []uint64{}
97 for _, input := range tpl.Transaction.Inputs {
98 gotInput = append(gotInput, input.Amount())
101 gotOutput := []uint64{}
102 for _, output := range tpl.Transaction.Outputs {
103 gotOutput = append(gotOutput, output.AssetAmount().Amount)
106 if !testutil.DeepEqual(c.wantInput[i], gotInput) {
107 t.Errorf("case %d tx %d input got %d want %d", caseIndex, i, gotInput, c.wantInput[i])
109 if !testutil.DeepEqual(c.wantOutput[i], gotOutput) {
110 t.Errorf("case %d tx %d output got %d want %d", caseIndex, i, gotOutput, c.wantOutput[i])
114 if c.wantUtxo != gotUtxo.Amount {
115 t.Errorf("case %d got utxo=%d want utxo=%d", caseIndex, gotUtxo.Amount, c.wantUtxo)