mirror of
https://github.com/status-im/go-waku.git
synced 2025-02-26 20:10:44 +00:00
chore: RLN tests coverage improvement for node gm (#1009)
This commit is contained in:
parent
0723ff9282
commit
190d8e8e08
@ -1,6 +1,10 @@
|
|||||||
package node
|
package node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
||||||
|
r "github.com/waku-org/go-zerokit-rln/rln"
|
||||||
|
"go.uber.org/zap"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -14,6 +18,15 @@ import (
|
|||||||
"github.com/waku-org/go-waku/waku/v2/protocol/store"
|
"github.com/waku-org/go-waku/waku/v2/protocol/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func handleSpam(msg *pb.WakuMessage, topic string) error {
|
||||||
|
|
||||||
|
logger := new(zap.Logger)
|
||||||
|
|
||||||
|
logger.Log(zap.InfoLevel, "Spam has been detected!")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestWakuOptions(t *testing.T) {
|
func TestWakuOptions(t *testing.T) {
|
||||||
connStatusChan := make(chan ConnStatus, 100)
|
connStatusChan := make(chan ConnStatus, 100)
|
||||||
|
|
||||||
@ -59,3 +72,101 @@ func TestWakuOptions(t *testing.T) {
|
|||||||
require.NotNil(t, params.privKey)
|
require.NotNil(t, params.privKey)
|
||||||
require.NotNil(t, params.connStatusC)
|
require.NotNil(t, params.connStatusC)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWakuRLNOptions(t *testing.T) {
|
||||||
|
connStatusChan := make(chan ConnStatus, 100)
|
||||||
|
|
||||||
|
key, err := tests.RandomHex(32)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
prvKey, err := crypto.HexToECDSA(key)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
||||||
|
|
||||||
|
addr, err := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/4000/ws")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
storeFactory := func(w *WakuNode) store.Store {
|
||||||
|
return store.NewWakuStore(w.opts.messageProvider, w.peermanager, w.timesource, prometheus.DefaultRegisterer, w.log)
|
||||||
|
}
|
||||||
|
|
||||||
|
index := r.MembershipIndex(5)
|
||||||
|
|
||||||
|
// Test WithStaticRLNRelay
|
||||||
|
|
||||||
|
options := []WakuNodeOption{
|
||||||
|
WithHostAddress(hostAddr),
|
||||||
|
WithAdvertiseAddresses(addr),
|
||||||
|
WithMultiaddress(addr),
|
||||||
|
WithPrivateKey(prvKey),
|
||||||
|
WithLibP2POptions(),
|
||||||
|
WithWakuRelay(),
|
||||||
|
WithLegacyWakuFilter(true),
|
||||||
|
WithDiscoveryV5(123, nil, false),
|
||||||
|
WithWakuStore(),
|
||||||
|
WithMessageProvider(&persistence.DBStore{}),
|
||||||
|
WithLightPush(),
|
||||||
|
WithKeepAlive(time.Hour),
|
||||||
|
WithConnectionStatusChannel(connStatusChan),
|
||||||
|
WithWakuStoreFactory(storeFactory),
|
||||||
|
WithStaticRLNRelay(&index, handleSpam),
|
||||||
|
}
|
||||||
|
|
||||||
|
params := new(WakuNodeParameters)
|
||||||
|
|
||||||
|
for _, opt := range options {
|
||||||
|
require.NoError(t, opt(params))
|
||||||
|
}
|
||||||
|
|
||||||
|
require.True(t, params.enableRLN)
|
||||||
|
require.False(t, params.rlnRelayDynamic)
|
||||||
|
require.Equal(t, uint(5), *params.rlnRelayMemIndex)
|
||||||
|
require.NotNil(t, params.rlnSpamHandler)
|
||||||
|
|
||||||
|
// Test WithDynamicRLNRelay
|
||||||
|
|
||||||
|
var (
|
||||||
|
keystorePath = "./rlnKeystore.json"
|
||||||
|
keystorePassword = "password"
|
||||||
|
rlnTreePath = "root"
|
||||||
|
contractAddress = "0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4"
|
||||||
|
ethClientAddress = "wss://sepolia.infura.io/ws/v3/API_KEY_GOES_HERE"
|
||||||
|
)
|
||||||
|
|
||||||
|
index = uint(0)
|
||||||
|
|
||||||
|
options2 := []WakuNodeOption{
|
||||||
|
WithHostAddress(hostAddr),
|
||||||
|
WithAdvertiseAddresses(addr),
|
||||||
|
WithMultiaddress(addr),
|
||||||
|
WithPrivateKey(prvKey),
|
||||||
|
WithLibP2POptions(),
|
||||||
|
WithWakuRelay(),
|
||||||
|
WithLegacyWakuFilter(true),
|
||||||
|
WithDiscoveryV5(123, nil, false),
|
||||||
|
WithWakuStore(),
|
||||||
|
WithMessageProvider(&persistence.DBStore{}),
|
||||||
|
WithLightPush(),
|
||||||
|
WithKeepAlive(time.Hour),
|
||||||
|
WithConnectionStatusChannel(connStatusChan),
|
||||||
|
WithWakuStoreFactory(storeFactory),
|
||||||
|
WithDynamicRLNRelay(keystorePath, keystorePassword, rlnTreePath, common.HexToAddress(contractAddress), &index, handleSpam, ethClientAddress),
|
||||||
|
}
|
||||||
|
|
||||||
|
params2 := new(WakuNodeParameters)
|
||||||
|
|
||||||
|
for _, opt := range options2 {
|
||||||
|
require.NoError(t, opt(params2))
|
||||||
|
}
|
||||||
|
|
||||||
|
require.True(t, params2.enableRLN)
|
||||||
|
require.True(t, params2.rlnRelayDynamic)
|
||||||
|
require.Equal(t, keystorePassword, params2.keystorePassword)
|
||||||
|
require.Equal(t, uint(0), *params2.rlnRelayMemIndex)
|
||||||
|
require.NotNil(t, params2.rlnSpamHandler)
|
||||||
|
require.Equal(t, ethClientAddress, params2.rlnETHClientAddress)
|
||||||
|
require.Equal(t, common.HexToAddress(contractAddress), params2.rlnMembershipContractAddress)
|
||||||
|
require.Equal(t, rlnTreePath, params2.rlnTreePath)
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -331,3 +331,54 @@ func (s *WakuRLNRelayDynamicSuite) tmpRLNDBPath() string {
|
|||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
return dbPath
|
return dbPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagerGetters() {
|
||||||
|
// Create a RLN instance
|
||||||
|
rlnInstance, err := rln.NewRLN()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
rt := group_manager.NewMerkleRootTracker(5, rlnInstance)
|
||||||
|
|
||||||
|
u1Credentials := s.generateCredentials(rlnInstance)
|
||||||
|
appKeystore, err := keystore.New(s.tmpKeystorePath(), dynamic.RLNAppInfo, utils.Logger())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
membershipIndex := s.register(appKeystore, u1Credentials, s.u1PrivKey)
|
||||||
|
|
||||||
|
gm, err := dynamic.NewDynamicGroupManager(s.web3Config.ETHClientAddress, s.web3Config.RegistryContract.Address, &membershipIndex, appKeystore, keystorePassword, prometheus.DefaultRegisterer, rlnInstance, rt, utils.Logger())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// initialize the WakuRLNRelay
|
||||||
|
rlnRelay := &WakuRLNRelay{
|
||||||
|
Details: group_manager.Details{
|
||||||
|
RootTracker: rt,
|
||||||
|
GroupManager: gm,
|
||||||
|
RLN: rlnInstance,
|
||||||
|
},
|
||||||
|
log: utils.Logger(),
|
||||||
|
nullifierLog: NewNullifierLog(ctx, utils.Logger()),
|
||||||
|
}
|
||||||
|
|
||||||
|
err = rlnRelay.Start(ctx)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// Test IdentityCredentials
|
||||||
|
_, err = gm.IdentityCredentials()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// Test MembershipIndex
|
||||||
|
mIndex := gm.MembershipIndex()
|
||||||
|
s.Require().Equal(mIndex, uint(membershipIndex))
|
||||||
|
|
||||||
|
// Test IsReady
|
||||||
|
isReady, err := gm.IsReady(ctx)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().True(isReady)
|
||||||
|
|
||||||
|
// Test Stop / gm.Start happened as a part of rlnRelay.Start
|
||||||
|
err = gm.Stop()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user