swarm/swap: GetPeerBalance test; add TODO for chequebook API check

This commit is contained in:
Fabio Barone 2018-11-12 07:52:54 -05:00
parent 9e8f2c470f
commit a42ce93bd7
2 changed files with 30 additions and 0 deletions

View file

@ -45,6 +45,34 @@ func init() {
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true)))) 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 //Test that repeated bookings do correct accounting
func TestRepeatedBookings(t *testing.T) { func TestRepeatedBookings(t *testing.T) {
//create a test swap account //create a test swap account

View file

@ -363,6 +363,8 @@ func (self *Swarm) Start(srv *p2p.Server) error {
newaddr := self.bzz.UpdateLocalAddr([]byte(srv.Self().String())) 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)) log.Info("Updated bzz local addr", "oaddr", fmt.Sprintf("%x", newaddr.OAddr), "uaddr", fmt.Sprintf("%s", newaddr.UAddr))
// set chequebook // 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 != "" { if self.config.SwapEnabled && self.config.SwapAPI != "" {
ctx := context.Background() // The initial setup has no deadline. ctx := context.Background() // The initial setup has no deadline.
err := self.SetChequebook(ctx) err := self.SetChequebook(ctx)