Skip to content

Commit

Permalink
sik: fix test
Browse files Browse the repository at this point in the history
The current approach only removes valid SIKs if there are changes on the
SIKs tree. If there isn't, besides the height increases, the SIK roots
remain valid.

Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Nov 7, 2023
1 parent 62788d2 commit 81f4573
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions vochain/state/sik_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ func Test_sikRoots(t *testing.T) {
c.Assert(s.SetAddressSIK(address1, sik1), qt.IsNil)
c.Assert(s.UpdateSIKRoots(), qt.IsNil)
// check the results
c.Assert(s.FetchValidSIKRoots(), qt.IsNil)
c.Assert(s.UpdateSIKRoots(), qt.IsNil)
validSIKs := s.ValidSIKRoots()
c.Assert(err, qt.IsNil)
c.Assert(len(validSIKs), qt.Equals, 1)
sikTree, err := s.tx.DeepSubTree(StateTreeCfg(TreeSIK))
c.Assert(err, qt.IsNil)
firstRoot, err := sikTree.Root()
c.Assert(err, qt.IsNil)
t.Logf("first root: %x", firstRoot)
t.Logf("valid sik: %x", validSIKs[0])
t.Logf("valid sik size: %d", len(validSIKs))
c.Assert(firstRoot, qt.ContentEquals, validSIKs[0])
// increase the height and include a new sik
address2 := common.HexToAddress("0x5fb53c1f9b53fba0296f4e8306802d44235c1a11")
Expand All @@ -116,28 +119,28 @@ func Test_sikRoots(t *testing.T) {
c.Assert(s.SetAddressSIK(address2, sik2), qt.IsNil)
c.Assert(s.UpdateSIKRoots(), qt.IsNil)
// check the results
c.Assert(s.FetchValidSIKRoots(), qt.IsNil)
c.Assert(s.UpdateSIKRoots(), qt.IsNil)
validSIKs = s.ValidSIKRoots()
c.Assert(err, qt.IsNil)
c.Assert(len(validSIKs), qt.Equals, 2)
secondRoot, err := sikTree.Root()
c.Assert(err, qt.IsNil)
c.Assert(firstRoot, qt.ContentEquals, validSIKs[0])
c.Assert(secondRoot, qt.ContentEquals, validSIKs[1])
// increase the height and include a new sik that will delete the rest of sikroots
// increase the height and include a new sik
address3 := common.HexToAddress("0x2dd603151d817f829b03412f7378e1179b5b2b1c")
sik3, _ := hex.DecodeString("7ccbc0da9e8d7e469ba60cd898a5b881c99a960c1e69990a3196")
s.SetHeight(66)
c.Assert(s.SetAddressSIK(address3, sik3), qt.IsNil)
c.Assert(s.UpdateSIKRoots(), qt.IsNil)
// check the results
c.Assert(s.FetchValidSIKRoots(), qt.IsNil)
c.Assert(s.UpdateSIKRoots(), qt.IsNil)
validSIKs = s.ValidSIKRoots()
c.Assert(err, qt.IsNil)
c.Assert(len(validSIKs), qt.Equals, 1)
c.Assert(len(validSIKs), qt.Equals, 3)
thirdRoot, err := sikTree.Root()
c.Assert(err, qt.IsNil)
c.Assert(thirdRoot, qt.ContentEquals, validSIKs[0])
c.Assert(thirdRoot, qt.ContentEquals, validSIKs[2])
}

func TestAssignSIKToElectionAndPurge(t *testing.T) {
Expand Down

0 comments on commit 81f4573

Please sign in to comment.