From 6de61b5d4378dfac3aca1e3e78d73ae327028643 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 13 May 2018 14:23:20 -0400 Subject: [PATCH] Sharding: Add check if already deposited Former-commit-id: 32d3ec5c6bcbeb8e77aa7873e395e2b2cd362571 [formerly 623faf56f979a6e3f7bf4f903aac5c967da40dd2] Former-commit-id: 5a60c62411845f441bca4f0a5540cf79ad9e0658 --- sharding/notary/notary.go | 4 ++++ sharding/notary/notary_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/sharding/notary/notary.go b/sharding/notary/notary.go index dd428e97a..7573ed9d3 100644 --- a/sharding/notary/notary.go +++ b/sharding/notary/notary.go @@ -140,6 +140,10 @@ func joinNotaryPool(c client.Client) error { return errors.New("joinNotaryPool called when deposit flag was not set") } + if b, err := isAccountInNotaryPool(c); b || err != nil { + return err + } + log.Info("Joining notary pool") txOps, err := c.CreateTXOpts(sharding.NotaryDeposit) if err != nil { diff --git a/sharding/notary/notary_test.go b/sharding/notary/notary_test.go index a32e5d6ea..21fa7d6fd 100644 --- a/sharding/notary/notary_test.go +++ b/sharding/notary/notary_test.go @@ -138,4 +138,20 @@ func TestJoinNotaryPool(t *testing.T) { if big.NewInt(1).Cmp(numNotaries) != 0 { t.Fatalf("Unexpected number of notaries. Got %d, wanted 1.", numNotaries) } + + // Trying to join while deposited should do nothing + err = joinNotaryPool(client) + if err != nil { + t.Error(err) + } + backend.Commit() + + numNotaries, err = smc.NotaryPoolLength(&bind.CallOpts{}) + if err != nil { + t.Fatal(err) + } + if big.NewInt(1).Cmp(numNotaries) != 0 { + t.Fatalf("Unexpected number of notaries. Got %d, wanted 1.", numNotaries) + } + }