9 func TestMergeActions(t *testing.T) {
18 {"type": "spend_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount":100, "account_id": "123"},
19 {"type": "spend_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","amount": 200,"account_id": "123"},
20 {"type": "control_receiver", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount": 200, "receiver":{"control_program": "program","expires_at":"2017"}}
28 {"type": "spend_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount":100, "account_id": "123"},
29 {"type": "spend_account", "asset_id": "43c6946d092b2959c1a82e90b282c68fca63e66de289048f6acd6cea9383c79c","amount": 200,"account_id": "123"},
30 {"type": "control_receiver", "asset_id": "43c6946d092b2959c1a82e90b282c68fca63e66de289048f6acd6cea9383c79c", "amount": 200, "receiver":{"control_program": "program","expires_at":"2017"}}
37 {"type": "spend_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount":100, "account_id": "123"},
38 {"type": "spend_account", "asset_id": "43c6946d092b2959c1a82e90b282c68fca63e66de289048f6acd6cea9383c79c","amount": 200,"account_id": "123"},
39 {"type": "spend_account", "asset_id": "43c6946d092b2959c1a82e90b282c68fca63e66de289048f6acd6cea9383c79c","amount": 300,"account_id": "123"},
40 {"type": "control_receiver", "asset_id": "43c6946d092b2959c1a82e90b282c68fca63e66de289048f6acd6cea9383c79c", "amount": 500, "receiver":{"control_program": "program","expires_at":"2017"}}
48 {"type": "spend_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "amount":100, "account_id": "123"},
49 {"type": "spend_account", "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","amount": 200,"account_id": "123"},
50 {"type": "spend_account", "asset_id": "43c6946d092b2959c1a82e90b282c68fca63e66de289048f6acd6cea9383c79c","amount": 200,"account_id": "123"},
51 {"type": "spend_account", "asset_id": "43c6946d092b2959c1a82e90b282c68fca63e66de289048f6acd6cea9383c79c","amount": 300,"account_id": "123"},
52 {"type": "control_receiver", "asset_id": "43c6946d092b2959c1a82e90b282c68fca63e66de289048f6acd6cea9383c79c", "amount": 500, "receiver":{"control_program": "program","expires_at":"2017"}}
60 for i, c := range cases {
61 BuildReq := &BuildRequest{}
63 if err := json.Unmarshal([]byte(c.buildStr), BuildReq); err != nil {
67 for _, m := range BuildReq.Actions {
68 amount := m["amount"].(float64)
69 m["amount"] = json.Number(fmt.Sprintf("%v", amount))
72 actions := mergeActions(BuildReq)
74 if len(actions) != c.actionCount {
75 t.Fatalf("got error count %d, want %d", len(actions), c.actionCount)
78 for _, a := range actions {
79 actionType := a["type"].(string)
80 assetID := a["asset_id"].(string)
81 if actionType == "spend_account" {
82 amountNumber := a["amount"].(json.Number)
83 amount, _ := amountNumber.Int64()
86 case "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff":
87 if amount != c.wantBTM {
88 t.Fatalf("index %d, get error amount %v, want %d", i, amount, c.wantBTM)
90 case "43c6946d092b2959c1a82e90b282c68fca63e66de289048f6acd6cea9383c79c":
91 if amount != c.wantOther {
92 t.Fatalf("index %d, get error amount %v, want %d", i, amount, c.wantOther)
95 t.Fatalf("no %s in test cases", assetID)