func TestAccountingAddBalance(t *testing.T) {
	logger := logging.New(ioutil.Discard, 0)
	store := mock.NewStateStore()
	defer store.Close()
	acc, err := accounting.NewAccounting(testPaymentThreshold, testPaymentTolerance, testPaymentEarly, logger, store, nil, big.NewInt(testRefreshRate), p2pmock.New())
	if err != nil {
		t.Fatal(err)
	}
	peer1Addr, err := swarm.ParseHexAddress("00112233")
	if err != nil {
		t.Fatal(err)
	}
	peer2Addr, err := swarm.ParseHexAddress("00112244")
	if err != nil {
		t.Fatal(err)
	}
	acc.Connect(peer1Addr)
	acc.Connect(peer2Addr)
	bookings := []booking{
		{peer: peer1Addr, price: 100, expectedBalance: 100},
		{peer: peer2Addr, price: 200, expectedBalance: 200},
		{peer: peer1Addr, price: 300, expectedBalance: 400},
		{peer: peer1Addr, price: -100, expectedBalance: 300},
		{peer: peer2Addr, price: -1000, expectedBalance: -800},
	}
	for i, booking := range bookings {
		if booking.price < 0 {
			err = acc.Reserve(context.Background(), booking.peer, uint64(-booking.price))
			if err != nil {
				t.Fatal(err)
			}
			err = acc.Credit(booking.peer, uint64(-booking.price), true)
			if err != nil {
				t.Fatal(err)
			}
			acc.Release(booking.peer, uint64(-booking.price))
		} else {
			debitAction, err := acc.PrepareDebit(booking.peer, uint64(booking.price))
			if err != nil {
				t.Fatal(err)
			}
			err = debitAction.Apply()
			if err != nil {
				t.Fatal(err)
			}
			debitAction.Cleanup()
		}
		balance, err := acc.Balance(booking.peer)
		if err != nil {
			t.Fatal(err)
		}
		if balance.Int64() != booking.expectedBalance {
			t.Fatalf("balance for peer %v not as expected after booking %d. got %d, wanted %d", booking.peer.String(), i, balance, booking.expectedBalance)
		}
	}
}
TestAccountingAddBalance does several accounting actions and verifies the balance after each steep
package accounting_test
import (
	"context"
	"errors"
	"io/ioutil"
	"math/big"
	"testing"
	"time"
	"github.com/ethsana/sana/pkg/accounting"
	"github.com/ethsana/sana/pkg/logging"
	"github.com/ethsana/sana/pkg/p2p"
	p2pmock "github.com/ethsana/sana/pkg/p2p/mock"
	"github.com/ethsana/sana/pkg/statestore/mock"
	"github.com/ethsana/sana/pkg/swarm"
)
const (
	testPrice       = uint64(10)
	testRefreshRate = int64(1000)
)
var (
	testPaymentTolerance = big.NewInt(1000)
	testPaymentEarly     = big.NewInt(1000)
	testPaymentThreshold = big.NewInt(10000)
)
type paymentCall struct {
	peer   swarm.Address
	amount *big.Int
}
type booking struct {
	peer              swarm.Address
	price             int64  
	expectedBalance   int64
	originatedBalance int64
	originatedCredit  bool
	notifyPaymentSent bool
	overpay           uint64
}