Skip to content

Commit

Permalink
CNS-337: add testing of plan proposal and subscription
Browse files Browse the repository at this point in the history
Signed-off-by: Oren Laadan <[email protected]>
  • Loading branch information
orenl-lava committed May 2, 2023
1 parent 2c5e3bd commit caf47ad
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
11 changes: 10 additions & 1 deletion scripts/init_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ __dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $__dir/useful_commands.sh

GASPRICE="0.000000001ulava"

# Specs proposal
lavad tx gov submit-proposal spec-add ./cookbook/specs/spec_add_ethereum.json,./cookbook/specs/spec_add_ibc.json,./cookbook/specs/spec_add_cosmossdk.json,./cookbook/specs/spec_add_lava.json -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE
lavad tx gov vote 1 yes -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE
sleep 4

# Plans proposal
lavad tx gov submit-proposal plans-add ./cookbook/plans/default.json -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE
lavad tx gov vote 2 yes -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE
sleep 4

STAKE="500000000000ulava"
# Ethereum providers
lavad tx pairing stake-provider "ETH1" $STAKE "127.0.0.1:2221,jsonrpc,1" 1 -y --from servicer1 --provider-moniker "dummyMoniker" --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE
Expand All @@ -25,5 +32,7 @@ lavad tx pairing stake-provider "LAV1" $STAKE "127.0.0.1:2265,tendermintrpc,1 12
lavad tx pairing stake-client "ETH1" $STAKE 1 -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE
lavad tx pairing stake-client "LAV1" $STAKE 1 -y --from user2 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE

lavad tx subscription buy "DefaultPlan" -y --from user3 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE

# we need to wait for the next epoch for the stake to take action.
sleep_until_next_epoch
sleep_until_next_epoch
4 changes: 2 additions & 2 deletions testutil/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This E2E performs the steps below to test if the system is working as expected.

1. Start lava in developer mode (equivalent to running the command "ignite chain serve" ).
2. Check if lava is done booting up by sending a GRPC request.
3. Send Spec proposals and stake providers and clients.
3. Send Spec and Plan proposals and stake providers and clients.
4. Check if the proposals and stakes are properly executed.
5. Start the JSONRPC Proxy.
6. Start the JSONRPC Provider.
Expand All @@ -30,4 +30,4 @@ After the steps above are finished (even if a step fails and the E2E ends) the E

# Allowed Error List

The allowed error list contains a list of errors that is allowed to happen during tests. The key is the error substring that can be seen in the logs. The value is the description on why this error is allowed.
The allowed error list contains a list of errors that is allowed to happen during tests. The key is the error substring that can be seen in the logs. The value is the description on why this error is allowed.
42 changes: 37 additions & 5 deletions testutil/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/lavanet/lava/utils"
epochStorageTypes "github.com/lavanet/lava/x/epochstorage/types"
pairingTypes "github.com/lavanet/lava/x/pairing/types"
planTypes "github.com/lavanet/lava/x/plans/types"
specTypes "github.com/lavanet/lava/x/spec/types"
tmclient "github.com/tendermint/tendermint/rpc/client/http"
"golang.org/x/exp/slices"
Expand All @@ -41,6 +42,7 @@ const (
)

var (
checkedPlansE2E = []string{"DefaultPlan"}
checkedSpecsE2E = []string{"LAV1", "ETH1"}
checkedSpecsE2ELOL = []string{"GTH1"}
)
Expand Down Expand Up @@ -165,7 +167,34 @@ func (lt *lavaTest) stakeLava() {
cmd.Wait()
}

func (lt *lavaTest) checkStakeLava(specCount int, providerCount int, clientCount int, checkedSpecs []string, successMessage string) {
func (lt *lavaTest) checkStakeLava(
planCount int,
specCount int,
providerCount int,
clientCount int,
checkedPlans []string,
checkedSpecs []string,
successMessage string,
) {
planQueryClient := planTypes.NewQueryClient(lt.grpcConn)

// query all plans
planQueryRes, err := planQueryClient.List(context.Background(), &planTypes.QueryListRequest{})
if err != nil {
panic(err)
}

// check if plans added exist
if len(planQueryRes.PlansInfo) != planCount {
panic("Staking Failed PLAN count")
}

for _, plan := range planQueryRes.PlansInfo {
if !slices.Contains(checkedPlans, plan.Index) {
panic("Staking Failed PLAN names")
}
}

// providerCount and clientCount refers to number and providers and client for each spec
// number of providers and clients should be the same for all specs for simplicity's sake
specQueryClient := specTypes.NewQueryClient(lt.grpcConn)
Expand Down Expand Up @@ -517,7 +546,7 @@ func (lt *lavaTest) lavaOverLava(ctx context.Context) {
// - produce 4 specs: ETH1, GTH1, IBC, COSMOSSDK, LAV1 (via spec_add_{ethereum,cosmoshub,lava})
// - produce 1 plan: "DefaultPlan"

lt.checkStakeLava(5, 5, 1, checkedSpecsE2ELOL, "Lava Over Lava Test OK")
lt.checkStakeLava(1, 5, 5, 1, checkedPlansE2E, checkedSpecsE2ELOL, "Lava Over Lava Test OK")
}

func (lt *lavaTest) checkRESTConsumer(rpcURL string, timeout time.Duration) {
Expand Down Expand Up @@ -781,9 +810,12 @@ func runE2E() {
utils.LavaFormatInfo("Starting Lava OK")
utils.LavaFormatInfo("Staking Lava")
lt.stakeLava()
// scripts/init_e2e.sh adds spec_add_{ethereum,cosmoshub,lava}, which
// produce 4 specs: ETH1, GTH1, IBC, COSMOSSDK, LAV1
lt.checkStakeLava(5, 5, 1, checkedSpecsE2E, "Staking Lava OK")

// scripts/init_e2e.sh will:
// - produce 4 specs: ETH1, GTH1, IBC, COSMOSSDK, LAV1 (via spec_add_{ethereum,cosmoshub,lava})
// - produce 1 plan: "DefaultPlan"

lt.checkStakeLava(1, 5, 5, 1, checkedPlansE2E, checkedSpecsE2E, "Staking Lava OK")

utils.LavaFormatInfo("RUNNING TESTS")

Expand Down

0 comments on commit caf47ad

Please sign in to comment.