prysm-pulse/sharding/notary/service_test.go
Preston Van Loon 77267169ea Add More Lint Rules With gometalinter (#284)
* turn up linter to 11

* Added extra linting rules and fixed all lint issues

* add deadline of 10m


Former-commit-id: 632999fcaa8370516d6fe76c28c503cb2e3319b7 [formerly d4354f631b1eb4f7918cde28bf063f756ae92a54]
Former-commit-id: 3aaf78a56b76850b0123d61551ac554ccecfe9ad
2018-07-15 15:06:36 -04:00

102 lines
2.6 KiB
Go

package notary
import (
"math/big"
"testing"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/prysmaticlabs/geth-sharding/sharding/internal"
shardparams "github.com/prysmaticlabs/geth-sharding/sharding/params"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
)
// Verifies that Notary implements the Actor interface.
var _ = types.Actor(&Notary{})
func TestHasAccountBeenDeregistered(t *testing.T) {
backend, smc := internal.SetupMockClient(t)
client := &internal.MockClient{SMC: smc, T: t, Backend: backend, BlockNumber: 1}
client.SetDepositFlag(true)
err := joinNotaryPool(client, client)
if err != nil {
t.Error(err)
}
}
func TestIsAccountInNotaryPool(t *testing.T) {
backend, smc := internal.SetupMockClient(t)
client := &internal.MockClient{SMC: smc, T: t, Backend: backend}
// address should not be in pool initially.
b, err := isAccountInNotaryPool(client, client.Account())
if err != nil {
t.Fatal(err)
}
if b {
t.Fatal("account unexpectedly in notary pool")
}
txOpts, _ := client.CreateTXOpts(shardparams.DefaultConfig.NotaryDeposit)
if _, err := smc.RegisterNotary(txOpts); err != nil {
t.Fatalf("Failed to deposit: %v", err)
}
client.CommitWithBlock()
b, err = isAccountInNotaryPool(client, client.Account())
if err != nil {
t.Error(err)
}
if !b {
t.Error("account not in notary pool when expected to be")
}
}
func TestJoinNotaryPool(t *testing.T) {
backend, smc := internal.SetupMockClient(t)
client := &internal.MockClient{SMC: smc, T: t, Backend: backend}
// There should be no notary initially.
numNotaries, err := smc.NotaryPoolLength(&bind.CallOpts{})
if err != nil {
t.Error(err)
}
if big.NewInt(0).Cmp(numNotaries) != 0 {
t.Errorf("unexpected number of notaries. Got %d, wanted 0.", numNotaries)
}
client.SetDepositFlag(false)
err = joinNotaryPool(client, client)
if err == nil {
t.Error("joined notary pool while --deposit was not present")
}
client.SetDepositFlag(true)
err = joinNotaryPool(client, client)
if err != nil {
t.Error(err)
}
// Now there should be one notary.
numNotaries, err = smc.NotaryPoolLength(&bind.CallOpts{})
if err != nil {
t.Error(err)
}
if big.NewInt(1).Cmp(numNotaries) != 0 {
t.Errorf("unexpected number of notaries. Got %d, wanted 1", numNotaries)
}
// Join while deposited should do nothing.
err = joinNotaryPool(client, client)
if err != nil {
t.Error(err)
}
numNotaries, err = smc.NotaryPoolLength(&bind.CallOpts{})
if err != nil {
t.Error(err)
}
if big.NewInt(1).Cmp(numNotaries) != 0 {
t.Errorf("unexpected number of notaries. Got %d, wanted 1", numNotaries)
}
}