test: delete members with atomic_operation

This commit is contained in:
Richard Ramos 2023-07-28 16:19:08 -04:00
parent 86b06ba440
commit a93a03ebfc
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
2 changed files with 45 additions and 3 deletions

View File

@ -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
}

View File

@ -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)
}