mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
swarm/swap: GetPeerBalance test; add TODO for chequebook API check
This commit is contained in:
parent
9e8f2c470f
commit
a42ce93bd7
2 changed files with 30 additions and 0 deletions
|
|
@ -45,6 +45,34 @@ func init() {
|
|||
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true))))
|
||||
}
|
||||
|
||||
//Test getting a peer's balance
|
||||
func TestGetPeerBalance(t *testing.T) {
|
||||
//create a test swap account
|
||||
swap, testDir := createTestSwap(t)
|
||||
defer os.RemoveAll(testDir)
|
||||
|
||||
//test for correct value
|
||||
testPeer := newDummyPeer()
|
||||
swap.balances[testPeer.ID()] = 888
|
||||
b, err := swap.GetPeerBalance(testPeer.ID())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b != 888 {
|
||||
t.Fatalf("Expected peer's balance to be %d, but is %d", 888, b)
|
||||
}
|
||||
|
||||
//test for inexistent node
|
||||
id := adapters.RandomNodeConfig().ID
|
||||
_, err = swap.GetPeerBalance(id)
|
||||
if err == nil {
|
||||
t.Fatal("Expected call to fail, but it didn't!")
|
||||
}
|
||||
if err.Error() != "Peer not found" {
|
||||
t.Fatalf("Expected test to fail with %s, but is %s", "Peer not found", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
//Test that repeated bookings do correct accounting
|
||||
func TestRepeatedBookings(t *testing.T) {
|
||||
//create a test swap account
|
||||
|
|
|
|||
|
|
@ -363,6 +363,8 @@ func (self *Swarm) Start(srv *p2p.Server) error {
|
|||
newaddr := self.bzz.UpdateLocalAddr([]byte(srv.Self().String()))
|
||||
log.Info("Updated bzz local addr", "oaddr", fmt.Sprintf("%x", newaddr.OAddr), "uaddr", fmt.Sprintf("%s", newaddr.UAddr))
|
||||
// set chequebook
|
||||
//TODO: Currently if swap is enabled and no chequebook (or inexistent) contract is provided, the node would crash.
|
||||
//Once we integrate back the contracts, this check MUST be revisited
|
||||
if self.config.SwapEnabled && self.config.SwapAPI != "" {
|
||||
ctx := context.Background() // The initial setup has no deadline.
|
||||
err := self.SetChequebook(ctx)
|
||||
|
|
|
|||
Loading…
Reference in a new issue