From a93a03ebfc081e2a45201787fcd558423dfd0790 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 28 Jul 2023 16:19:08 -0400 Subject: [PATCH] test: delete members with atomic_operation --- rln/rln.go | 27 ++++++++++++++++++++++++--- rln/rln_test.go | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/rln/rln.go b/rln/rln.go index 5a0a9bb..7d25dad 100644 --- a/rln/rln.go +++ b/rln/rln.go @@ -3,6 +3,7 @@ package rln import "C" import ( "encoding/binary" + "encoding/hex" "errors" "fmt" @@ -282,7 +283,17 @@ func (r *RLN) InsertMember(idComm IDCommitment) error { func (r *RLN) InsertMembers(index MembershipIndex, idComms []IDCommitment) error { idCommBytes := serializeCommitments(idComms) indicesBytes := serializeIndices(nil) + + fmt.Println("--------------") + fmt.Println("Sending the following values to atomic_operation:") + fmt.Println("* START: ", index) + fmt.Println("* LEAVES: ", hex.EncodeToString(idCommBytes)) + fmt.Println("* INDICES: ", hex.EncodeToString(indicesBytes)) + insertionSuccess := r.w.AtomicOperation(index, idCommBytes, indicesBytes) + fmt.Println("\n* EXECUTION RESULT SUCCESSFUL: ", insertionSuccess) + fmt.Println("--------------") + if !insertionSuccess { return errors.New("could not insert members") } @@ -304,9 +315,19 @@ func (r *RLN) DeleteMember(index MembershipIndex) error { func (r *RLN) DeleteMembers(indices []MembershipIndex) error { idCommBytes := serializeCommitments(nil) indicesBytes := serializeIndices(indices) - insertionSuccess := r.w.AtomicOperation(0, idCommBytes, indicesBytes) - if !insertionSuccess { - return errors.New("could not insert members") + + fmt.Println("--------------") + fmt.Println("Sending the following values to atomic_operation:") + fmt.Println("* START: ", 0) + fmt.Println("* LEAVES: ", hex.EncodeToString(idCommBytes)) + fmt.Println("* INDICES: ", hex.EncodeToString(indicesBytes)) + + deleteSuccess := r.w.AtomicOperation(0, idCommBytes, indicesBytes) + fmt.Println("\n* EXECUTION RESULT SUCCESSFUL: ", deleteSuccess) + fmt.Println("--------------") + + if !deleteSuccess { + return errors.New("could not delete members") } return nil } diff --git a/rln/rln_test.go b/rln/rln_test.go index 5b0b454..df73097 100644 --- a/rln/rln_test.go +++ b/rln/rln_test.go @@ -300,3 +300,24 @@ func (s *RLNSuite) TestEpochComparison() { s.Equal(int64(1), Diff(epoch1, epoch2)) s.Equal(int64(-1), Diff(epoch2, epoch1)) } + +func (s *RLNSuite) TestDeleteMembersWithAtomicWrite() { + rln, err := NewRLN() + s.NoError(err) + + var commitments []IDCommitment + + // Create a Merkle tree with random members + for i := 0; i < 3; i++ { + // create a new key pair + memberKeys, err := rln.MembershipKeyGen() + s.NoError(err) + commitments = append(commitments, memberKeys.IDCommitment) + } + + err = rln.InsertMembers(0, commitments) // If inserting members from scratch, should the index be 0 or 1? + s.NoError(err) + + err = rln.DeleteMembers([]uint{2}) // This should delete index 2, but fails + s.NoError(err) +}