9 dbm "github.com/tendermint/tmlibs/db"
11 "github.com/bytom/accesstoken"
12 "github.com/bytom/blockchain/rpc"
13 "github.com/bytom/testutil"
16 func TestAPIHandler(t *testing.T) {
18 response := &Response{}
20 // init httptest server
22 server := httptest.NewServer(a.handler)
25 // create accessTokens
26 testDB := dbm.NewDB("testdb", "leveldb", "temp")
27 defer os.RemoveAll("temp")
28 a.accessTokens = accesstoken.NewStore(testDB)
30 client := &rpc.Client{
32 AccessToken: "test-user:test-secret",
43 Alias string `json:"alias"`
44 Password string `json:"password"`
45 }{Alias: "alice", Password: "123456"},
48 Msg: "wallet not found, please check that the wallet is open",
56 Msg: "wallet not found, please check that the wallet is open",
68 path: "/create-access-token",
71 Type string `json:"type"`
72 }{ID: "test-access-id", Type: "test-access-type"},
76 Data: map[string]interface{}{"id": "test-access-id", "type": "test-access-type", "token": "test-access-id:440d87ae0d625a7fcf076275b18372e09a0899e37ec86398879388de90cb0c67"},
85 Data: map[string]interface{}{"gasRate": 1000},
90 for _, c := range cases {
91 response = &Response{}
92 client.Call(context.Background(), c.path, c.request, &response)
94 if !testutil.DeepEqual(response.Status, c.respWant.Status) {
95 t.Errorf(`got=%#v; want=%#v`, response.Status, c.respWant.Status)