test: wallet proxy, chain scanner tests
daemon/wallet_rpc_test.go: IsWalletMethod routing, proxy creation wallet/chain_scanner_test.go: scanner creation, empty range scan Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
a328c9f859
commit
4b797efc9e
2 changed files with 64 additions and 0 deletions
31
daemon/wallet_rpc_test.go
Normal file
31
daemon/wallet_rpc_test.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package daemon
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestWalletProxy_IsWalletMethod_Good(t *testing.T) {
|
||||
walletMethods := []string{"getbalance", "getaddress", "transfer", "deploy_asset", "register_alias"}
|
||||
for _, m := range walletMethods {
|
||||
if !IsWalletMethod(m) {
|
||||
t.Errorf("%s should be a wallet method", m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWalletProxy_IsWalletMethod_Bad(t *testing.T) {
|
||||
chainMethods := []string{"getinfo", "getheight", "get_all_alias_details", "search"}
|
||||
for _, m := range chainMethods {
|
||||
if IsWalletMethod(m) {
|
||||
t.Errorf("%s should NOT be a wallet method", m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWalletProxy_New_Good(t *testing.T) {
|
||||
proxy := NewWalletProxy("http://127.0.0.1:46944")
|
||||
if proxy == nil {
|
||||
t.Fatal("proxy is nil")
|
||||
}
|
||||
if proxy.walletURL != "http://127.0.0.1:46944" {
|
||||
t.Errorf("url: %s", proxy.walletURL)
|
||||
}
|
||||
}
|
||||
33
wallet/chain_scanner_test.go
Normal file
33
wallet/chain_scanner_test.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package wallet
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"dappco.re/go/core/blockchain/types"
|
||||
)
|
||||
|
||||
func TestChainScanner_New_Good(t *testing.T) {
|
||||
account, _ := GenerateAccount()
|
||||
getter := func(h uint64) (*types.Block, []types.Transaction, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
scanner := NewChainScanner(account, getter)
|
||||
if scanner == nil {
|
||||
t.Fatal("scanner is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChainScanner_ScanRange_Empty_Good(t *testing.T) {
|
||||
account, _ := GenerateAccount()
|
||||
getter := func(h uint64) (*types.Block, []types.Transaction, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
scanner := NewChainScanner(account, getter)
|
||||
transfers, scanned := scanner.ScanRange(0, 10)
|
||||
if len(transfers) != 0 {
|
||||
t.Errorf("expected 0 transfers, got %d", len(transfers))
|
||||
}
|
||||
if scanned != 0 {
|
||||
t.Errorf("expected 0 scanned (nil blocks), got %d", scanned)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue