|
| 1 | +/* |
| 2 | + * Copyright (c) 2018 LI Zhennan |
| 3 | + * |
| 4 | + * Use of this work is governed by a MIT License. |
| 5 | + * You may find a license copy in project root. |
| 6 | + */ |
| 7 | + |
| 8 | +package etherscan |
| 9 | + |
| 10 | +import ( |
| 11 | + "encoding/json" |
| 12 | + "fmt" |
| 13 | + "math/big" |
| 14 | + "testing" |
| 15 | +) |
| 16 | + |
| 17 | +func TestClient_AccountBalance(t *testing.T) { |
| 18 | + balance, err := api.AccountBalance("0x281055afc982d96fab65b3a49cac8b878184cb16") |
| 19 | + noError(t, err, "api.AccountBalance") |
| 20 | + |
| 21 | + if balance.Int().Cmp(big.NewInt(0)) != 1 { |
| 22 | + t.Fatalf("rich man is no longer rich") |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func TestClient_MultiAccountBalance(t *testing.T) { |
| 27 | + balances, err := api.MultiAccountBalance( |
| 28 | + "0x281055afc982d96fab65b3a49cac8b878184cb16", |
| 29 | + "0x6f46cf5569aefa1acc1009290c8e043747172d89", |
| 30 | + "0x90e63c3d53e0ea496845b7a03ec7548b70014a91", |
| 31 | + "0x53d284357ec70ce289d6d64134dfac8e511c8a3d") |
| 32 | + noError(t, err, "api.MultiAccountBalance") |
| 33 | + |
| 34 | + for i, item := range balances { |
| 35 | + if item.Account == "" { |
| 36 | + t.Errorf("bound error on index %v", i) |
| 37 | + } |
| 38 | + if item.Balance.Int().Cmp(big.NewInt(0)) != 1 { |
| 39 | + t.Errorf("rich man %s at index %v is no longer rich.", item.Account, i) |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +func TestClient_NormalTxByAddress(t *testing.T) { |
| 45 | + const wantLen = 19 |
| 46 | + |
| 47 | + var a, b = 54092, 79728 |
| 48 | + txs, err := api.NormalTxByAddress("0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", &a, &b, 1, 500, false) |
| 49 | + noError(t, err, "api.NormalTxByAddress") |
| 50 | + |
| 51 | + //j, _ := json.MarshalIndent(txs, "", " ") |
| 52 | + //fmt.Printf("%s\n", j) |
| 53 | + |
| 54 | + if len(txs) != wantLen { |
| 55 | + t.Errorf("got txs length %v, want %v", len(txs), wantLen) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func TestClient_InternalTxByAddress(t *testing.T) { |
| 60 | + const wantLen = 66 |
| 61 | + |
| 62 | + var a, b = 0, 2702578 |
| 63 | + txs, err := api.InternalTxByAddress("0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3", &a, &b, 1, 500, false) |
| 64 | + noError(t, err, "api.InternalTxByAddress") |
| 65 | + |
| 66 | + //j, _ := json.MarshalIndent(txs, "", " ") |
| 67 | + //fmt.Printf("%s\n", j) |
| 68 | + |
| 69 | + if len(txs) != wantLen { |
| 70 | + t.Errorf("got txs length %v, want %v", len(txs), wantLen) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +func TestClient_ERC20TransferTx(t *testing.T) { |
| 75 | + const wantLen = 3 |
| 76 | + |
| 77 | + var a, b = 3273004, 3328071 |
| 78 | + var contract, address = "0xe0b7927c4af23765cb51314a0e0521a9645f0e2a", "0x4e83362442b8d1bec281594cea3050c8eb01311c" |
| 79 | + txs, err := api.ERC20TransferTx(&contract, &address, &a, &b, 1, 500) |
| 80 | + noError(t, err, "api.ERC20TransferTx") |
| 81 | + |
| 82 | + //j, _ := json.MarshalIndent(txs, "", " ") |
| 83 | + //fmt.Printf("%s\n", j) |
| 84 | + |
| 85 | + if len(txs) != wantLen { |
| 86 | + t.Errorf("got txs length %v, want %v", len(txs), wantLen) |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +func TestClient_BlocksMinedByAddress(t *testing.T) { |
| 91 | + const wantLen = 10 |
| 92 | + |
| 93 | + blocks, err := api.BlocksMinedByAddress("0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b", 1, wantLen) |
| 94 | + noError(t, err, "api.BlocksMinedByAddress") |
| 95 | + |
| 96 | + //j, _ := json.MarshalIndent(blocks, "", " ") |
| 97 | + //fmt.Printf("%s\n", j) |
| 98 | + |
| 99 | + if len(blocks) != wantLen { |
| 100 | + t.Errorf("got txs length %v, want %v", len(blocks), wantLen) |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +func TestClient_UnclesMinedByAddress(t *testing.T) { |
| 105 | + const wantLen = 10 |
| 106 | + |
| 107 | + blocks, err := api.UnclesMinedByAddress("0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b", 1, wantLen) |
| 108 | + noError(t, err, "api.UnclesMinedByAddress") |
| 109 | + |
| 110 | + j, _ := json.MarshalIndent(blocks, "", " ") |
| 111 | + fmt.Printf("%s\n", j) |
| 112 | + |
| 113 | + if len(blocks) != wantLen { |
| 114 | + t.Errorf("got txs length %v, want %v", len(blocks), wantLen) |
| 115 | + } |
| 116 | +} |
0 commit comments