mirror of
https://github.com/logos-messaging/go-zerokit-rln.git
synced 2026-01-02 13:13:11 +00:00
test: delete members with atomic_operation
This commit is contained in:
parent
86b06ba440
commit
a93a03ebfc
27
rln/rln.go
27
rln/rln.go
@ -3,6 +3,7 @@ package rln
|
|||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
@ -282,7 +283,17 @@ func (r *RLN) InsertMember(idComm IDCommitment) error {
|
|||||||
func (r *RLN) InsertMembers(index MembershipIndex, idComms []IDCommitment) error {
|
func (r *RLN) InsertMembers(index MembershipIndex, idComms []IDCommitment) error {
|
||||||
idCommBytes := serializeCommitments(idComms)
|
idCommBytes := serializeCommitments(idComms)
|
||||||
indicesBytes := serializeIndices(nil)
|
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)
|
insertionSuccess := r.w.AtomicOperation(index, idCommBytes, indicesBytes)
|
||||||
|
fmt.Println("\n* EXECUTION RESULT SUCCESSFUL: ", insertionSuccess)
|
||||||
|
fmt.Println("--------------")
|
||||||
|
|
||||||
if !insertionSuccess {
|
if !insertionSuccess {
|
||||||
return errors.New("could not insert members")
|
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 {
|
func (r *RLN) DeleteMembers(indices []MembershipIndex) error {
|
||||||
idCommBytes := serializeCommitments(nil)
|
idCommBytes := serializeCommitments(nil)
|
||||||
indicesBytes := serializeIndices(indices)
|
indicesBytes := serializeIndices(indices)
|
||||||
insertionSuccess := r.w.AtomicOperation(0, idCommBytes, indicesBytes)
|
|
||||||
if !insertionSuccess {
|
fmt.Println("--------------")
|
||||||
return errors.New("could not insert members")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -300,3 +300,24 @@ func (s *RLNSuite) TestEpochComparison() {
|
|||||||
s.Equal(int64(1), Diff(epoch1, epoch2))
|
s.Equal(int64(1), Diff(epoch1, epoch2))
|
||||||
s.Equal(int64(-1), Diff(epoch2, epoch1))
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user