7 "github.com/vapor/consensus"
8 "github.com/vapor/errors"
9 "github.com/vapor/protocol/bc"
12 func buildTxRequest(accountID string, outputs map[string]uint64) ([]byte, error) {
13 totalBTM := uint64(10000000)
14 actions := []interface{}{}
15 for address, amount := range outputs {
16 actions = append(actions, &ControlAddressAction{
18 AssetAmount: &bc.AssetAmount{AssetId: consensus.BTMAssetID, Amount: amount},
23 actions = append(actions, &SpendAccountAction{
25 AssetAmount: &bc.AssetAmount{AssetId: consensus.BTMAssetID, Amount: totalBTM},
27 payload, err := json.Marshal(&buildTxReq{Actions: actions})
29 return nil, errors.Wrap(err, "Marshal spend request")
37 outputs map[string]uint64
40 func TestBuildTxRequest(t *testing.T) {
47 accountID: "9bb77612-350e-4d53-81e2-525b28247ba5",
48 outputs: map[string]uint64{"sp1qlryy65a5apylphqp6axvhx7nd6y2zlexuvn7gf": 100},
50 want: `{"actions":[{"type":"control_address","address":"sp1qlryy65a5apylphqp6axvhx7nd6y2zlexuvn7gf","asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","amount":100},{"type":"spend_account","account_id":"9bb77612-350e-4d53-81e2-525b28247ba5","asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","amount":10000100}]}`,
54 accountID: "9bb77612-350e-4d53-81e2-525b28247ba5",
55 outputs: map[string]uint64{"sp1qlryy65a5apylphqp6axvhx7nd6y2zlexuvn7gf": 100, "sp1qcgtxkhfzytul4lfttwex3skfqhm0tg6ms9da28": 200},
57 want: `{"actions":[{"type":"control_address","address":"sp1qlryy65a5apylphqp6axvhx7nd6y2zlexuvn7gf","asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","amount":100},{"type":"control_address","address":"sp1qcgtxkhfzytul4lfttwex3skfqhm0tg6ms9da28","asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","amount":200},{"type":"spend_account","account_id":"9bb77612-350e-4d53-81e2-525b28247ba5","asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","amount":10000300}]}`,
61 for i, c := range cases {
62 tx, err := buildTxRequest(c.args.accountID, c.args.outputs)
66 if string(tx) != string(c.want) {
67 t.Fatal(i, string(tx))