11 dbm "github.com/tendermint/tmlibs/db"
13 "github.com/bytom/accesstoken"
14 "github.com/bytom/blockchain/rpc"
15 "github.com/bytom/blockchain/txbuilder"
16 "github.com/bytom/testutil"
19 func TestAPIHandler(t *testing.T) {
21 response := &Response{}
23 // init httptest server
25 server := httptest.NewServer(a.handler)
28 // create accessTokens
29 testDB := dbm.NewDB("testdb", "leveldb", "temp")
30 defer os.RemoveAll("temp")
31 a.accessTokens = accesstoken.NewStore(testDB)
33 client := &rpc.Client{
35 AccessToken: "test-user:test-secret",
46 Alias string `json:"alias"`
47 Password string `json:"password"`
48 }{Alias: "alice", Password: "123456"},
51 Msg: "wallet not found, please check that the wallet is open",
59 Msg: "wallet not found, please check that the wallet is open",
71 path: "/create-access-token",
74 Type string `json:"type"`
75 }{ID: "test-access-id", Type: "test-access-type"},
79 Data: map[string]interface{}{"id": "test-access-id", "type": "test-access-type", "token": "test-access-id:440d87ae0d625a7fcf076275b18372e09a0899e37ec86398879388de90cb0c67"},
88 Data: map[string]interface{}{"gasRate": 1000},
93 for _, c := range cases {
94 response = &Response{}
95 client.Call(context.Background(), c.path, c.request, &response)
97 if !testutil.DeepEqual(response.Status, c.respWant.Status) {
98 t.Errorf(`got=%#v; want=%#v`, response.Status, c.respWant.Status)
103 func TestEstimateTxGas(t *testing.T) {
104 tmplStr := `{"allow_additional_actions":false,"raw_transaction":"070100010161015ffe8a1209937a6a8b22e8c01f056fd5f1730734ba8964d6b79de4a639032cecddffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d59901000116001485eb6eee8023332da85df60157dc9b16cc553fb2010002013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80afa08b4f011600142b4fd033bc76b4ddf5cb00f625362c4bc7b10efa00013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8090dfc04a011600146eea1ce6cfa5b718ae8094376be9bc1a87c9c82700","signing_instructions":[{"position":0,"witness_components":[{"keys":[{"derivation_path":["010100000000000000","0100000000000000"],"xpub":"cb4e5932d808ee060df9552963d87f60edac42360b11d4ad89558ef2acea4d4aaf4818f2ebf5a599382b8dfce0a0c798c7e44ec2667b3a1d34c61ba57609de55"}],"quorum":1,"signatures":null,"type":"raw_tx_signature"},{"type":"data","value":"1c9b5c1db7f4afe31fd1b7e0495a8bb042a271d8d7924d4fc1ff7cf1bff15813"}]}]}`
105 template := txbuilder.Template{}
106 err := json.Unmarshal([]byte(tmplStr), &template)
111 estimateResult, err := EstimateTxGas(template)
116 baseRate := float64(100000)
117 totalNeu := float64(estimateResult.StorageNeu+estimateResult.VMNeu) / baseRate
118 roundingNeu := math.Ceil(totalNeu)
119 estimateNeu := int64(roundingNeu) * int64(baseRate)
121 if estimateResult.TotalNeu != estimateNeu {
122 t.Errorf(`got=%#v; want=%#v`, estimateResult.TotalNeu, estimateNeu)