-
Notifications
You must be signed in to change notification settings - Fork 19
/
transaction_pending_test.go
35 lines (29 loc) · 7.21 KB
/
transaction_pending_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package factom
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetPendingTransactions(t *testing.T) {
factomdResponse := `{
"jsonrpc":"2.0",
"id":0,
"result":[{"transactionid":"5d87f2ba00ebaee1b0aac86b97ab5a8d4ab5f07a948966856f5723b15c57a5ab","dbheight":12345,"status":"TransactionACK","inputs":null,"outputs":[{"amount":320000000,"address":"d06f8b5d84395afbec25d3aa3f3f2d5a6573ebd30e4d02e797d77107395c2b4a","useraddress":"FA3YsmVnBs2LwrthnFzEJYFTw2HzhYMmjnD2GtG6W2r2S2SvonCv"},{"amount":576000000,"address":"e8e41a1c7ca7c29dc928e509cae82cae1a4711eb12fddc8bde25bf1733069efc","useraddress":"FA3jeSpDq6JSNmizDS8TWwdxKS9EiKFeRCXyZNYrfH6eqX1K9o8u"},{"amount":320000000,"address":"6a437b1475d9455e8447f7b2a7f32044a28f5f16486d2f239eca5bdba02030c8","useraddress":"FA2msvDAoVgzRx8BTmxFAYDLbg2VQXqhi2HzKQHmsb4mVrKjY4B6"},{"amount":320000000,"address":"2b20273033acf00b40e88848a853a56dd0543570f4f28d30b050634d1e28bd6e","useraddress":"FA2J59Eb8xyizJLachFn8LuRXVsSNkoW2uPKrna8X4UrtyVwztgY"},{"amount":320000000,"address":"53c597f02efd7ef3caad48182969236a70883bada570aa316bc9b20efedcc73f","useraddress":"FA2byPxs4XYmra4Z6t3UcDwGaNP62LM631QarrqvVbrbsy9XCGoX"},{"amount":320000000,"address":"8f3064f2d1b8fac099719de1651e81c0fc3f0f29ef1a95a3b46c90e628b51ccc","useraddress":"FA3498SdD2tDAi2485czk6shCfU5Q3PC5Wsui6sNzxi1dTpwxpFj"},{"amount":320000000,"address":"d06f8b5d84395afbec25d3aa3f3f2d5a6573ebd30e4d02e797d77107395c2b4a","useraddress":"FA3YsmVnBs2LwrthnFzEJYFTw2HzhYMmjnD2GtG6W2r2S2SvonCv"},{"amount":320000000,"address":"6a437b1475d9455e8447f7b2a7f32044a28f5f16486d2f239eca5bdba02030c8","useraddress":"FA2msvDAoVgzRx8BTmxFAYDLbg2VQXqhi2HzKQHmsb4mVrKjY4B6"},{"amount":320000000,"address":"7e73ae9e7c31c632697e9c9207075a66f099f82f5d1da2aec157146d48c75533","useraddress":"FA2vmboi6PbPHdGjqG5PfRhCG1hcpkXqNkVigAmmjq9atUAA2NpZ"},{"amount":192000000,"address":"edef61cc4d07e34b64376c8ff5785274f84f191ae22224e90c8119d73727f3ce","useraddress":"FA3msHkoAH78cAVvdJE4Za6uSatPQR2aTgvSViRFN3vLBsixvkZQ"},{"amount":480000000,"address":"665650f5cfd74ec95bac1bc823dc7b7ab5b388a3b0ba31663cb678955e8146aa","useraddress":"FA2k9d61ujVHRRMkajk1pKteRSaqGUKf3iJyCBEbU6HeWe2sC5nx"},{"amount":320000000,"address":"cf681312cc74d91691e6c1be0df58c638145d877c6f1647c6ca8d88d2ffbfd17","useraddress":"FA3YRUjaGJjpjvNZPW7CCD7Ba7bJne25HdrTainPYotNw4rUoh46"},{"amount":640000000,"address":"cc26b2335e9b7c60bfd0e0e98d07ec7f58e67d54fb5717b86bbb868584ca1243","useraddress":"FA3WzKn5ygD8E2uGocAYhaooeQyehSjq1HC3hSb2EaJ4ZGfjku63"},{"amount":320000000,"address":"53c597f02efd7ef3caad48182969236a70883bada570aa316bc9b20efedcc73f","useraddress":"FA2byPxs4XYmra4Z6t3UcDwGaNP62LM631QarrqvVbrbsy9XCGoX"}],"ecoutputs":null,"fees":0},{"transactionid":"3a1e8dc38ef4112bc3110ae47a02c417ba465a5478bf5b97a9b4fc842a9ce67a","dbheight":11111,"status":"TransactionACK","inputs":[{"amount":212000,"address":"d2e2860610e282b6d8d9fed05e2a8dce5d8211d86ca14e2edf05023f0759be97","useraddress":"FA3ZxKyN3HHoJftdGbFp5PRvi12jPvQ3SgGNTDQya2D5jwFrtLqZ"}],"outputs":[],"ecoutputs":[{"amount":200000,"address":"3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29","useraddress":"EC2DKSYyRcNWf7RS963VFYgMExoHRYLHVeCfQ9PGPmNzwrcmgm2r"}],"fees":12000},{"transactionid":"0b3f7feadcc849c60bdad4ccac4b831039c6321cecb6667a8d39a8c14850e5cc","dbheight":54321,"status":"TransactionACK","inputs":[{"amount":500012000,"address":"d2e2860610e282b6d8d9fed05e2a8dce5d8211d86ca14e2edf05023f0759be97","useraddress":"FA3ZxKyN3HHoJftdGbFp5PRvi12jPvQ3SgGNTDQya2D5jwFrtLqZ"}],"outputs":[{"amount":500000000,"address":"646f3e8750c550e4582eca5047546ffef89c13a175985e320232bacac81cc428","useraddress":"FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q"}],"ecoutputs":[],"fees":12000}]
}`
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, factomdResponse)
}))
defer ts.Close()
SetFactomdServer(ts.URL[7:])
response, err := GetPendingTransactions()
if err != nil {
t.Error(err)
}
got := fmt.Sprintf("%+v", response)
want := `[{TxID:5d87f2ba00ebaee1b0aac86b97ab5a8d4ab5f07a948966856f5723b15c57a5ab DBHeight:12345 Status:TransactionACK Fees:0 Inputs:[] Outputs:[{Amount:320000000 RCDHash:d06f8b5d84395afbec25d3aa3f3f2d5a6573ebd30e4d02e797d77107395c2b4a Address:FA3YsmVnBs2LwrthnFzEJYFTw2HzhYMmjnD2GtG6W2r2S2SvonCv} {Amount:576000000 RCDHash:e8e41a1c7ca7c29dc928e509cae82cae1a4711eb12fddc8bde25bf1733069efc Address:FA3jeSpDq6JSNmizDS8TWwdxKS9EiKFeRCXyZNYrfH6eqX1K9o8u} {Amount:320000000 RCDHash:6a437b1475d9455e8447f7b2a7f32044a28f5f16486d2f239eca5bdba02030c8 Address:FA2msvDAoVgzRx8BTmxFAYDLbg2VQXqhi2HzKQHmsb4mVrKjY4B6} {Amount:320000000 RCDHash:2b20273033acf00b40e88848a853a56dd0543570f4f28d30b050634d1e28bd6e Address:FA2J59Eb8xyizJLachFn8LuRXVsSNkoW2uPKrna8X4UrtyVwztgY} {Amount:320000000 RCDHash:53c597f02efd7ef3caad48182969236a70883bada570aa316bc9b20efedcc73f Address:FA2byPxs4XYmra4Z6t3UcDwGaNP62LM631QarrqvVbrbsy9XCGoX} {Amount:320000000 RCDHash:8f3064f2d1b8fac099719de1651e81c0fc3f0f29ef1a95a3b46c90e628b51ccc Address:FA3498SdD2tDAi2485czk6shCfU5Q3PC5Wsui6sNzxi1dTpwxpFj} {Amount:320000000 RCDHash:d06f8b5d84395afbec25d3aa3f3f2d5a6573ebd30e4d02e797d77107395c2b4a Address:FA3YsmVnBs2LwrthnFzEJYFTw2HzhYMmjnD2GtG6W2r2S2SvonCv} {Amount:320000000 RCDHash:6a437b1475d9455e8447f7b2a7f32044a28f5f16486d2f239eca5bdba02030c8 Address:FA2msvDAoVgzRx8BTmxFAYDLbg2VQXqhi2HzKQHmsb4mVrKjY4B6} {Amount:320000000 RCDHash:7e73ae9e7c31c632697e9c9207075a66f099f82f5d1da2aec157146d48c75533 Address:FA2vmboi6PbPHdGjqG5PfRhCG1hcpkXqNkVigAmmjq9atUAA2NpZ} {Amount:192000000 RCDHash:edef61cc4d07e34b64376c8ff5785274f84f191ae22224e90c8119d73727f3ce Address:FA3msHkoAH78cAVvdJE4Za6uSatPQR2aTgvSViRFN3vLBsixvkZQ} {Amount:480000000 RCDHash:665650f5cfd74ec95bac1bc823dc7b7ab5b388a3b0ba31663cb678955e8146aa Address:FA2k9d61ujVHRRMkajk1pKteRSaqGUKf3iJyCBEbU6HeWe2sC5nx} {Amount:320000000 RCDHash:cf681312cc74d91691e6c1be0df58c638145d877c6f1647c6ca8d88d2ffbfd17 Address:FA3YRUjaGJjpjvNZPW7CCD7Ba7bJne25HdrTainPYotNw4rUoh46} {Amount:640000000 RCDHash:cc26b2335e9b7c60bfd0e0e98d07ec7f58e67d54fb5717b86bbb868584ca1243 Address:FA3WzKn5ygD8E2uGocAYhaooeQyehSjq1HC3hSb2EaJ4ZGfjku63} {Amount:320000000 RCDHash:53c597f02efd7ef3caad48182969236a70883bada570aa316bc9b20efedcc73f Address:FA2byPxs4XYmra4Z6t3UcDwGaNP62LM631QarrqvVbrbsy9XCGoX}] ECOutputs:[]} {TxID:3a1e8dc38ef4112bc3110ae47a02c417ba465a5478bf5b97a9b4fc842a9ce67a DBHeight:11111 Status:TransactionACK Fees:12000 Inputs:[{Amount:212000 RCDHash:d2e2860610e282b6d8d9fed05e2a8dce5d8211d86ca14e2edf05023f0759be97 Address:FA3ZxKyN3HHoJftdGbFp5PRvi12jPvQ3SgGNTDQya2D5jwFrtLqZ}] Outputs:[] ECOutputs:[{Amount:200000 RCDHash:3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29 Address:EC2DKSYyRcNWf7RS963VFYgMExoHRYLHVeCfQ9PGPmNzwrcmgm2r}]} {TxID:0b3f7feadcc849c60bdad4ccac4b831039c6321cecb6667a8d39a8c14850e5cc DBHeight:54321 Status:TransactionACK Fees:12000 Inputs:[{Amount:500012000 RCDHash:d2e2860610e282b6d8d9fed05e2a8dce5d8211d86ca14e2edf05023f0759be97 Address:FA3ZxKyN3HHoJftdGbFp5PRvi12jPvQ3SgGNTDQya2D5jwFrtLqZ}] Outputs:[{Amount:500000000 RCDHash:646f3e8750c550e4582eca5047546ffef89c13a175985e320232bacac81cc428 Address:FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q}] ECOutputs:[]}]`
if got != want {
t.Errorf("unexpected response. got = %s, want = %s", got, want)
}
}