9 "github.com/vapor/accesstoken"
10 "github.com/vapor/blockchain/rpc"
11 dbm "github.com/vapor/database/leveldb"
12 "github.com/vapor/testutil"
15 func TestAPIHandler(t *testing.T) {
17 response := &Response{}
19 // init httptest server
21 server := httptest.NewServer(a.handler)
24 // create accessTokens
25 testDB := dbm.NewDB("testdb", "leveldb", "temp")
26 defer os.RemoveAll("temp")
27 a.accessTokens = accesstoken.NewStore(testDB)
29 client := &rpc.Client{
31 AccessToken: "test-user:test-secret",
42 Alias string `json:"alias"`
43 Password string `json:"password"`
44 }{Alias: "alice", Password: "123456"},
47 Msg: "wallet not found, please check that the wallet is open",
55 Msg: "wallet not found, please check that the wallet is open",
67 path: "/create-access-token",
70 Type string `json:"type"`
71 }{ID: "test-access-id", Type: "test-access-type"},
75 Data: map[string]interface{}{"id": "test-access-id", "type": "test-access-type", "token": "test-access-id:440d87ae0d625a7fcf076275b18372e09a0899e37ec86398879388de90cb0c67"},
84 Data: map[string]interface{}{"gasRate": 1000},
89 for _, c := range cases {
90 response = &Response{}
91 client.Call(context.Background(), c.path, c.request, &response)
93 if !testutil.DeepEqual(response.Status, c.respWant.Status) {
94 t.Errorf(`got=%#v; want=%#v`, response.Status, c.respWant.Status)