From a086fe2a9fc8465e03eb3797f270f9414019d58d Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Wed, 29 Mar 2023 18:05:56 +0800 Subject: [PATCH 1/9] CNS-337: fix permissions of lava_fullFlow_test.go file Signed-off-by: Oren Laadan --- testutil/e2e/lava_fullFlow_test.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 testutil/e2e/lava_fullFlow_test.go diff --git a/testutil/e2e/lava_fullFlow_test.go b/testutil/e2e/lava_fullFlow_test.go old mode 100755 new mode 100644 From 54b66f29819ec3af3cd00274873326c3ad82550a Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Sun, 2 Apr 2023 11:42:40 +0800 Subject: [PATCH 2/9] CNS-337: fix whitespace in e2e yml --- .../e2e/e2eProviderConfigs/ethConsumer.yml | 6 ++-- .../e2eProviderConfigs/jsonrpcProvider1.yml | 11 +++---- .../e2eProviderConfigs/jsonrpcProvider2.yml | 11 +++---- .../e2eProviderConfigs/jsonrpcProvider3.yml | 11 +++---- .../e2eProviderConfigs/jsonrpcProvider4.yml | 11 +++---- .../e2eProviderConfigs/jsonrpcProvider5.yml | 11 +++---- .../e2e/e2eProviderConfigs/lavaConsumer.yml | 19 ++++++----- .../e2e/e2eProviderConfigs/lavaProvider10.yml | 32 +++++++++---------- .../e2e/e2eProviderConfigs/lavaProvider6.yml | 32 +++++++++---------- .../e2e/e2eProviderConfigs/lavaProvider7.yml | 32 +++++++++---------- .../e2e/e2eProviderConfigs/lavaProvider8.yml | 32 +++++++++---------- .../e2e/e2eProviderConfigs/lavaProvider9.yml | 32 +++++++++---------- 12 files changed, 117 insertions(+), 123 deletions(-) diff --git a/testutil/e2e/e2eProviderConfigs/ethConsumer.yml b/testutil/e2e/e2eProviderConfigs/ethConsumer.yml index dc017a8cd0..a19b7f308a 100644 --- a/testutil/e2e/e2eProviderConfigs/ethConsumer.yml +++ b/testutil/e2e/e2eProviderConfigs/ethConsumer.yml @@ -1,4 +1,4 @@ endpoints: - - chain-id: ETH1 - api-interface: jsonrpc - network-address: 127.0.0.1:3333 \ No newline at end of file + - chain-id: ETH1 + api-interface: jsonrpc + network-address: 127.0.0.1:3333 diff --git a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider1.yml b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider1.yml index 053f6f8db3..56b1b53ad1 100644 --- a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider1.yml +++ b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider1.yml @@ -1,7 +1,6 @@ endpoints: - - api-interface: jsonrpc - chain-id: ETH1 - network-address: 127.0.0.1:2221 - node-urls: - - url: http://127.0.0.1:1111 - \ No newline at end of file + - api-interface: jsonrpc + chain-id: ETH1 + network-address: 127.0.0.1:2221 + node-urls: + - url: http://127.0.0.1:1111 diff --git a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider2.yml b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider2.yml index 580d7a95a6..4b359dfdfe 100644 --- a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider2.yml +++ b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider2.yml @@ -1,7 +1,6 @@ endpoints: - - api-interface: jsonrpc - chain-id: ETH1 - network-address: 127.0.0.1:2222 - node-urls: - - url: http://127.0.0.1:1111 - \ No newline at end of file + - api-interface: jsonrpc + chain-id: ETH1 + network-address: 127.0.0.1:2222 + node-urls: + - url: http://127.0.0.1:1111 diff --git a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider3.yml b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider3.yml index ac9b54ec83..0062f4bc06 100644 --- a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider3.yml +++ b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider3.yml @@ -1,7 +1,6 @@ endpoints: - - api-interface: jsonrpc - chain-id: ETH1 - network-address: 127.0.0.1:2223 - node-urls: - - url: http://127.0.0.1:1111 - \ No newline at end of file + - api-interface: jsonrpc + chain-id: ETH1 + network-address: 127.0.0.1:2223 + node-urls: + - url: http://127.0.0.1:1111 diff --git a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider4.yml b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider4.yml index ef1e0b77e5..8e94d3e85b 100644 --- a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider4.yml +++ b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider4.yml @@ -1,7 +1,6 @@ endpoints: - - api-interface: jsonrpc - chain-id: ETH1 - network-address: 127.0.0.1:2224 - node-urls: - - url: http://127.0.0.1:1111 - \ No newline at end of file + - api-interface: jsonrpc + chain-id: ETH1 + network-address: 127.0.0.1:2224 + node-urls: + - url: http://127.0.0.1:1111 diff --git a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider5.yml b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider5.yml index 9b3431caa1..7d3c19431f 100644 --- a/testutil/e2e/e2eProviderConfigs/jsonrpcProvider5.yml +++ b/testutil/e2e/e2eProviderConfigs/jsonrpcProvider5.yml @@ -1,7 +1,6 @@ endpoints: - - api-interface: jsonrpc - chain-id: ETH1 - network-address: 127.0.0.1:2225 - node-urls: - - url: http://127.0.0.1:1111 - \ No newline at end of file + - api-interface: jsonrpc + chain-id: ETH1 + network-address: 127.0.0.1:2225 + node-urls: + - url: http://127.0.0.1:1111 diff --git a/testutil/e2e/e2eProviderConfigs/lavaConsumer.yml b/testutil/e2e/e2eProviderConfigs/lavaConsumer.yml index d44c13e8a9..f31f2f4c85 100644 --- a/testutil/e2e/e2eProviderConfigs/lavaConsumer.yml +++ b/testutil/e2e/e2eProviderConfigs/lavaConsumer.yml @@ -1,11 +1,10 @@ endpoints: - - chain-id: LAV1 - api-interface: tendermintrpc - network-address: 127.0.0.1:3340 - - chain-id: LAV1 - api-interface: rest - network-address: 127.0.0.1:3341 - - chain-id: LAV1 - api-interface: grpc - network-address: 127.0.0.1:3342 - \ No newline at end of file + - chain-id: LAV1 + api-interface: tendermintrpc + network-address: 127.0.0.1:3340 + - chain-id: LAV1 + api-interface: rest + network-address: 127.0.0.1:3341 + - chain-id: LAV1 + api-interface: grpc + network-address: 127.0.0.1:3342 diff --git a/testutil/e2e/e2eProviderConfigs/lavaProvider10.yml b/testutil/e2e/e2eProviderConfigs/lavaProvider10.yml index 0c77dc3c65..612f58151a 100644 --- a/testutil/e2e/e2eProviderConfigs/lavaProvider10.yml +++ b/testutil/e2e/e2eProviderConfigs/lavaProvider10.yml @@ -1,17 +1,17 @@ endpoints: - - api-interface: tendermintrpc - chain-id: LAV1 - network-address: 127.0.0.1:2265 - node-urls: - - url: ws://0.0.0.0:26657/websocket - - url: http://0.0.0.0:26657 - - api-interface: rest - chain-id: LAV1 - network-address: 127.0.0.1:2275 - node-urls: - - url: http://127.0.0.1:1317 - - api-interface: grpc - chain-id: LAV1 - network-address: 127.0.0.1:2285 - node-urls: - - url: 127.0.0.1:9090 + - api-interface: tendermintrpc + chain-id: LAV1 + network-address: 127.0.0.1:2265 + node-urls: + - url: ws://0.0.0.0:26657/websocket + - url: http://0.0.0.0:26657 + - api-interface: rest + chain-id: LAV1 + network-address: 127.0.0.1:2275 + node-urls: + - url: http://127.0.0.1:1317 + - api-interface: grpc + chain-id: LAV1 + network-address: 127.0.0.1:2285 + node-urls: + - url: 127.0.0.1:9090 diff --git a/testutil/e2e/e2eProviderConfigs/lavaProvider6.yml b/testutil/e2e/e2eProviderConfigs/lavaProvider6.yml index 7ea15ae18e..8446d0dd8f 100644 --- a/testutil/e2e/e2eProviderConfigs/lavaProvider6.yml +++ b/testutil/e2e/e2eProviderConfigs/lavaProvider6.yml @@ -1,17 +1,17 @@ endpoints: - - api-interface: tendermintrpc - chain-id: LAV1 - network-address: 127.0.0.1:2261 - node-urls: - - url: ws://0.0.0.0:26657/websocket - - url: http://0.0.0.0:26657 - - api-interface: rest - chain-id: LAV1 - network-address: 127.0.0.1:2271 - node-urls: - - url: http://127.0.0.1:1317 - - api-interface: grpc - chain-id: LAV1 - network-address: 127.0.0.1:2281 - node-urls: - - url: 127.0.0.1:9090 + - api-interface: tendermintrpc + chain-id: LAV1 + network-address: 127.0.0.1:2261 + node-urls: + - url: ws://0.0.0.0:26657/websocket + - url: http://0.0.0.0:26657 + - api-interface: rest + chain-id: LAV1 + network-address: 127.0.0.1:2271 + node-urls: + - url: http://127.0.0.1:1317 + - api-interface: grpc + chain-id: LAV1 + network-address: 127.0.0.1:2281 + node-urls: + - url: 127.0.0.1:9090 diff --git a/testutil/e2e/e2eProviderConfigs/lavaProvider7.yml b/testutil/e2e/e2eProviderConfigs/lavaProvider7.yml index 29c31c9485..fde4495fea 100644 --- a/testutil/e2e/e2eProviderConfigs/lavaProvider7.yml +++ b/testutil/e2e/e2eProviderConfigs/lavaProvider7.yml @@ -1,17 +1,17 @@ endpoints: - - api-interface: tendermintrpc - chain-id: LAV1 - network-address: 127.0.0.1:2262 - node-urls: - - url: ws://0.0.0.0:26657/websocket - - url: http://0.0.0.0:26657 - - api-interface: rest - chain-id: LAV1 - network-address: 127.0.0.1:2272 - node-urls: - - url: http://127.0.0.1:1317 - - api-interface: grpc - chain-id: LAV1 - network-address: 127.0.0.1:2282 - node-urls: - - url: 127.0.0.1:9090 + - api-interface: tendermintrpc + chain-id: LAV1 + network-address: 127.0.0.1:2262 + node-urls: + - url: ws://0.0.0.0:26657/websocket + - url: http://0.0.0.0:26657 + - api-interface: rest + chain-id: LAV1 + network-address: 127.0.0.1:2272 + node-urls: + - url: http://127.0.0.1:1317 + - api-interface: grpc + chain-id: LAV1 + network-address: 127.0.0.1:2282 + node-urls: + - url: 127.0.0.1:9090 diff --git a/testutil/e2e/e2eProviderConfigs/lavaProvider8.yml b/testutil/e2e/e2eProviderConfigs/lavaProvider8.yml index c8e4723319..88f0b7aa79 100644 --- a/testutil/e2e/e2eProviderConfigs/lavaProvider8.yml +++ b/testutil/e2e/e2eProviderConfigs/lavaProvider8.yml @@ -1,17 +1,17 @@ endpoints: - - api-interface: tendermintrpc - chain-id: LAV1 - network-address: 127.0.0.1:2263 - node-urls: - - url: ws://0.0.0.0:26657/websocket - - url: http://0.0.0.0:26657 - - api-interface: rest - chain-id: LAV1 - network-address: 127.0.0.1:2273 - node-urls: - - url: http://127.0.0.1:1317 - - api-interface: grpc - chain-id: LAV1 - network-address: 127.0.0.1:2283 - node-urls: - - url: 127.0.0.1:9090 + - api-interface: tendermintrpc + chain-id: LAV1 + network-address: 127.0.0.1:2263 + node-urls: + - url: ws://0.0.0.0:26657/websocket + - url: http://0.0.0.0:26657 + - api-interface: rest + chain-id: LAV1 + network-address: 127.0.0.1:2273 + node-urls: + - url: http://127.0.0.1:1317 + - api-interface: grpc + chain-id: LAV1 + network-address: 127.0.0.1:2283 + node-urls: + - url: 127.0.0.1:9090 diff --git a/testutil/e2e/e2eProviderConfigs/lavaProvider9.yml b/testutil/e2e/e2eProviderConfigs/lavaProvider9.yml index 34682b60c9..02bd1fa1a4 100644 --- a/testutil/e2e/e2eProviderConfigs/lavaProvider9.yml +++ b/testutil/e2e/e2eProviderConfigs/lavaProvider9.yml @@ -1,17 +1,17 @@ endpoints: - - api-interface: tendermintrpc - chain-id: LAV1 - network-address: 127.0.0.1:2264 - node-urls: - - url: ws://0.0.0.0:26657/websocket - - url: http://0.0.0.0:26657 - - api-interface: rest - chain-id: LAV1 - network-address: 127.0.0.1:2274 - node-urls: - - url: http://127.0.0.1:1317 - - api-interface: grpc - chain-id: LAV1 - network-address: 127.0.0.1:2284 - node-urls: - - url: 127.0.0.1:9090 + - api-interface: tendermintrpc + chain-id: LAV1 + network-address: 127.0.0.1:2264 + node-urls: + - url: ws://0.0.0.0:26657/websocket + - url: http://0.0.0.0:26657 + - api-interface: rest + chain-id: LAV1 + network-address: 127.0.0.1:2274 + node-urls: + - url: http://127.0.0.1:1317 + - api-interface: grpc + chain-id: LAV1 + network-address: 127.0.0.1:2284 + node-urls: + - url: 127.0.0.1:9090 From 2c5e3bd514a63521d0a6e3e19e008f7601a26e2b Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Sun, 2 Apr 2023 14:28:03 +0800 Subject: [PATCH 3/9] CNS-337: refactor common pattern in e2e.go Introduce execCommand() helper for common code used in several functions. --- testutil/e2e/e2e.go | 234 +++++++----------- .../e2e/e2eProviderConfigs/ethConsumer.yml | 2 +- 2 files changed, 93 insertions(+), 143 deletions(-) diff --git a/testutil/e2e/e2e.go b/testutil/e2e/e2e.go index d2369a1f9d..0825ab79c4 100644 --- a/testutil/e2e/e2e.go +++ b/testutil/e2e/e2e.go @@ -15,7 +15,6 @@ import ( "path" "path/filepath" "runtime" - "strconv" "strings" "time" @@ -50,6 +49,7 @@ type lavaTest struct { testFinishedProperly bool grpcConn *grpc.ClientConn lavadPath string + lavadArgs string logs map[string]*bytes.Buffer commands map[string]*exec.Cmd providerType map[string][]epochStorageTypes.Endpoint @@ -67,6 +67,44 @@ func init() { fmt.Println("Test Directory", dir) } +func (lt *lavaTest) execCommand(ctx context.Context, funcName string, logName string, command string, wait bool) { + lt.logs[logName] = new(bytes.Buffer) + + cmd := exec.CommandContext(ctx, "", "") + cmd.Args = strings.Fields(command) + cmd.Path = cmd.Args[0] + cmd.Stdout = lt.logs[logName] + cmd.Stderr = lt.logs[logName] + + err := cmd.Start() + if err != nil { + panic(err) + } + + if wait { + if err = cmd.Wait(); err != nil { + panic(funcName + " failed " + err.Error()) + } + } else { + lt.commands[logName] = cmd + go func() { + lt.listenCmdCommand(cmd, funcName + " process returned unexpectedly", funcName) + }() + } +} + +func (lt *lavaTest) listenCmdCommand(cmd *exec.Cmd, panicReason string, functionName string) { + err := cmd.Wait() + if err != nil && !lt.testFinishedProperly { + utils.LavaFormatError(functionName+" cmd wait err", err) + } + if lt.testFinishedProperly { + return + } + lt.saveLogs() + panic(panicReason) +} + func (lt *lavaTest) startLava(ctx context.Context) { absPath, err := filepath.Abs(".") if err != nil { @@ -187,81 +225,43 @@ func (lt *lavaTest) startJSONRPCProxy(ctx context.Context) { if err != nil { panic("Could not find go executable path") } - proxyCommand := goExecutablePath + " test ./testutil/e2e/proxy/. -v eth" - lt.logs["02_jsonProxy"] = new(bytes.Buffer) + command := goExecutablePath + " test ./testutil/e2e/proxy/. -v eth" + logName := "02_jsonProxy" + funcName := "startJSONRPCProxy" - cmd := exec.CommandContext(ctx, "", "") - cmd.Path = goExecutablePath - cmd.Args = strings.Split(proxyCommand, " ") - cmd.Stdout = lt.logs["02_jsonProxy"] - cmd.Stderr = lt.logs["02_jsonProxy"] - - err = cmd.Start() - if err != nil { - panic(err) - } - lt.commands["02_jsonProxy"] = cmd - go func() { - lt.listenCmdCommand(cmd, "startJSONRPCProxy process returned unexpectedly", "startJSONRPCProxy") - }() - utils.LavaFormatInfo("startJSONRPCProxy OK") + lt.execCommand(ctx, funcName, logName, command, false) + utils.LavaFormatInfo(funcName + " OK") } func (lt *lavaTest) startJSONRPCProvider(ctx context.Context) { - providerCommands := []string{ - lt.lavadPath + " rpcprovider " + configFolder + "jsonrpcProvider1.yml --from servicer1 --geolocation 1 --log_level debug", - lt.lavadPath + " rpcprovider " + configFolder + "jsonrpcProvider2.yml --from servicer2 --geolocation 1 --log_level debug", - lt.lavadPath + " rpcprovider " + configFolder + "jsonrpcProvider3.yml --from servicer3 --geolocation 1 --log_level debug", - lt.lavadPath + " rpcprovider " + configFolder + "jsonrpcProvider4.yml --from servicer4 --geolocation 1 --log_level debug", - lt.lavadPath + " rpcprovider " + configFolder + "jsonrpcProvider5.yml --from servicer5 --geolocation 1 --log_level debug", - } - - for idx, providerCommand := range providerCommands { + for idx := 1; idx <= 5; idx++ { + command := fmt.Sprintf( + "%s rpcprovider %s/jsonrpcProvider%d.yml --from servicer%d %s", + lt.lavadPath, configFolder, idx, idx, lt.lavadArgs, + ) logName := "03_EthProvider_" + fmt.Sprintf("%02d", idx) - lt.logs[logName] = new(bytes.Buffer) - cmd := exec.CommandContext(ctx, "", "") - cmd.Path = lt.lavadPath - cmd.Args = strings.Split(providerCommand, " ") - cmd.Stdout = lt.logs[logName] - cmd.Stderr = lt.logs[logName] - - err := cmd.Start() - if err != nil { - panic(err) - } - lt.commands[logName] = cmd - go func(idx int) { - lt.listenCmdCommand(cmd, "startJSONRPCProvider process returned unexpectedly, provider idx:"+strconv.Itoa(idx), "startJSONRPCProvider") - }(idx) + funcName := fmt.Sprintf("startJSONRPCProvider (provider %02d)", idx) + lt.execCommand(ctx, funcName, logName, command, false) } + // validate all providers are up - for idx := 0; idx < len(providerCommands); idx++ { - lt.checkProviderResponsive(ctx, "127.0.0.1:222"+fmt.Sprintf("%d", idx+1), time.Minute) + for idx := 1; idx < 5; idx++ { + lt.checkProviderResponsive(ctx, fmt.Sprintf("127.0.0.1:222%d", idx), time.Minute) } utils.LavaFormatInfo("startJSONRPCProvider OK") } func (lt *lavaTest) startJSONRPCConsumer(ctx context.Context) { - providerCommand := lt.lavadPath + " rpcconsumer " + configFolder + "ethConsumer.yml --from user1 --geolocation 1 --log_level debug" - logName := "04_jsonConsumer" - lt.logs[logName] = new(bytes.Buffer) - - cmd := exec.CommandContext(ctx, "", "") - cmd.Path = lt.lavadPath - cmd.Args = strings.Split(providerCommand, " ") - cmd.Stdout = lt.logs[logName] - cmd.Stderr = lt.logs[logName] - - err := cmd.Start() - if err != nil { - panic(err) + for i, u := range []string{"user1"} { + command := fmt.Sprintf( + "%s rpcconsumer %s/ethConsumer.yml --from %s %s", + lt.lavadPath, configFolder, u, lt.lavadArgs, + ) + logName := "04_jsonConsumer_" + fmt.Sprintf("%02d", i+1) + funcName := fmt.Sprintf("startJSONRPCConsumer (consumer %02d)", i+1) + lt.execCommand(ctx, funcName, logName, command, false) } - - lt.commands[logName] = cmd - go func() { - lt.listenCmdCommand(cmd, "startJSONRPCConsumer process returned unexpectedly", "startJSONRPCConsumer") - }() utils.LavaFormatInfo("startJSONRPCConsumer OK") } @@ -406,63 +406,36 @@ func jsonrpcTests(rpcURL string, testDuration time.Duration) error { } func (lt *lavaTest) startLavaProviders(ctx context.Context) { - providerCommands := []string{ - lt.lavadPath + " rpcprovider " + configFolder + "lavaProvider6.yml --from servicer6 --geolocation 1 --log_level debug", - lt.lavadPath + " rpcprovider " + configFolder + "lavaProvider7.yml --from servicer7 --geolocation 1 --log_level debug", - lt.lavadPath + " rpcprovider " + configFolder + "lavaProvider8.yml --from servicer8 --geolocation 1 --log_level debug", - lt.lavadPath + " rpcprovider " + configFolder + "lavaProvider9.yml --from servicer9 --geolocation 1 --log_level debug", - lt.lavadPath + " rpcprovider " + configFolder + "lavaProvider10.yml --from servicer10 --geolocation 1 --log_level debug", - } - - for idx, providerCommand := range providerCommands { - logName := "05_LavaProvider_" + fmt.Sprintf("%02d", idx) - lt.logs[logName] = new(bytes.Buffer) - cmd := exec.CommandContext(ctx, "", "") - cmd.Path = lt.lavadPath - cmd.Args = strings.Split(providerCommand, " ") - cmd.Stdout = lt.logs[logName] - cmd.Stderr = lt.logs[logName] - - err := cmd.Start() - if err != nil { - panic(err) - } - lt.commands[logName] = cmd - - go func(idx int) { - lt.listenCmdCommand(cmd, "startLavaProviders process returned unexpectedly, provider idx:"+strconv.Itoa(idx), "startLavaProviders") - }(idx) + for idx := 6; idx <= 10; idx++ { + command := fmt.Sprintf( + "%s rpcprovider %s/lavaProvider%d --from servicer%d %s", + lt.lavadPath, configFolder, idx, idx, lt.lavadArgs, + ) + logName := "05_LavaProvider_" + fmt.Sprintf("%02d", idx-5) + funcName := fmt.Sprintf("startLavaProviders (provider %02d)", idx-5) + lt.execCommand(ctx, funcName, logName, command, false) } // validate all providers are up - for idx := 0; idx < len(providerCommands); idx++ { - lt.checkProviderResponsive(ctx, "127.0.0.1:226"+fmt.Sprintf("%d", idx+1), time.Minute) - lt.checkProviderResponsive(ctx, "127.0.0.1:227"+fmt.Sprintf("%d", idx+1), time.Minute) - lt.checkProviderResponsive(ctx, "127.0.0.1:228"+fmt.Sprintf("%d", idx+1), time.Minute) + for idx := 6; idx <= 10; idx++ { + lt.checkProviderResponsive(ctx, fmt.Sprintf("127.0.0.1:226%d", idx-5), time.Minute) + lt.checkProviderResponsive(ctx, fmt.Sprintf("127.0.0.1:227%d", idx-5), time.Minute) + lt.checkProviderResponsive(ctx, fmt.Sprintf("127.0.0.1:228%d", idx-5), time.Minute) } - utils.LavaFormatInfo("startTendermintProvider OK") + utils.LavaFormatInfo("startLavaProviders OK") } func (lt *lavaTest) startLavaConsumer(ctx context.Context) { - providerCommand := lt.lavadPath + " rpcconsumer " + configFolder + "lavaConsumer.yml --from user2 --geolocation 1 --log_level debug" - logName := "06_RPCConsumer" - lt.logs[logName] = new(bytes.Buffer) - - cmd := exec.CommandContext(ctx, "", "") - cmd.Path = lt.lavadPath - cmd.Args = strings.Split(providerCommand, " ") - cmd.Stdout = lt.logs[logName] - cmd.Stderr = lt.logs[logName] - - err := cmd.Start() - if err != nil { - panic(err) + for idx, u := range []string{"user2"} { + command := fmt.Sprintf( + "%s rpcconsumer %s/lavaConsumer.yml --from %s %s", + lt.lavadPath, configFolder, u, lt.lavadArgs, + ) + logName := "06_RPCConsumer_" + fmt.Sprintf("%02d", idx+1) + funcName := fmt.Sprintf("startRPCConsumer (consumer %02d)", idx+1) + lt.execCommand(ctx, funcName, logName, command, false) } - lt.commands[logName] = cmd - go func() { - lt.listenCmdCommand(cmd, "startRPCConsumer process returned unexpectedly", "startRPCConsumer") - }() utils.LavaFormatInfo("startRPCConsumer OK") } @@ -537,25 +510,13 @@ func tendermintURITests(rpcURL string, testDuration time.Duration) error { // This would submit a proposal, vote then stake providers and clients for that network over lava func (lt *lavaTest) lavaOverLava(ctx context.Context) { utils.LavaFormatInfo("Starting Lava over Lava Tests") - stakeCommand := "./scripts/init_e2e_lava_over_lava.sh" - logName := "07_lavaOverLava" - lt.logs[logName] = new(bytes.Buffer) - cmd := exec.CommandContext(ctx, "", "") - cmd.Path = stakeCommand - cmd.Args = strings.Split(stakeCommand, " ") - cmd.Stdout = lt.logs[logName] - cmd.Stderr = lt.logs[logName] + command := "./scripts/init_e2e_lava_over_lava.sh" + lt.execCommand(ctx, "startJSONRPCConsumer", "07_lavaOverLava", command, true) + + // scripts/init_e2e.sh will: + // - produce 4 specs: ETH1, GTH1, IBC, COSMOSSDK, LAV1 (via spec_add_{ethereum,cosmoshub,lava}) + // - produce 1 plan: "DefaultPlan" - err := cmd.Start() - if err != nil { - panic("Lava over Lava Failed " + err.Error()) - } - err = cmd.Wait() - if err != nil { - panic("Lava over Lava Failed " + err.Error()) - } - // scripts/init_e2e.sh adds spec_add_{ethereum,cosmoshub,lava}, which - // produce 4 specs: ETH1, GTH1, IBC, COSMOSSDK, LAV1 lt.checkStakeLava(5, 5, 1, checkedSpecsE2ELOL, "Lava Over Lava Test OK") } @@ -680,18 +641,6 @@ func (lt *lavaTest) finishTestSuccessfully() { } } -func (lt *lavaTest) listenCmdCommand(cmd *exec.Cmd, panicReason string, functionName string) { - err := cmd.Wait() - if err != nil && !lt.testFinishedProperly { - utils.LavaFormatError(functionName+" cmd wait err", err) - } - if lt.testFinishedProperly { - return - } - lt.saveLogs() - panic(panicReason) -} - func (lt *lavaTest) saveLogs() { if _, err := os.Stat(logsFolder); errors.Is(err, os.ErrNotExist) { err = os.MkdirAll(logsFolder, os.ModePerm) @@ -811,6 +760,7 @@ func runE2E() { lt := &lavaTest{ grpcConn: grpcConn, lavadPath: gopath + "/bin/lavad", + lavadArgs: "--geolocation 1 --log_level debug", logs: make(map[string]*bytes.Buffer), commands: make(map[string]*exec.Cmd), providerType: make(map[string][]epochStorageTypes.Endpoint), @@ -845,7 +795,7 @@ func runE2E() { lt.checkJSONRPCConsumer("http://127.0.0.1:1111", time.Minute*2, "JSONRPCProxy OK") // checks proxy. lt.startJSONRPCProvider(jsonCTX) lt.startJSONRPCConsumer(jsonCTX) - lt.checkJSONRPCConsumer("http://127.0.0.1:3333/1", time.Minute*2, "JSONRPCConsumer OK") + lt.checkJSONRPCConsumer("http://127.0.0.1:3331/1", time.Minute*2, "JSONRPCConsumer OK") // Lava Flow rpcCtx, cancel := context.WithCancel(context.Background()) @@ -857,7 +807,7 @@ func runE2E() { lt.checkRESTConsumer("http://127.0.0.1:3341/1", time.Second*30) lt.checkGRPCConsumer("127.0.0.1:3342", time.Second*30) - jsonErr := jsonrpcTests("http://127.0.0.1:3333/1", time.Second*30) + jsonErr := jsonrpcTests("http://127.0.0.1:3331/1", time.Second*30) if jsonErr != nil { panic(jsonErr) } else { diff --git a/testutil/e2e/e2eProviderConfigs/ethConsumer.yml b/testutil/e2e/e2eProviderConfigs/ethConsumer.yml index a19b7f308a..19ca80a55e 100644 --- a/testutil/e2e/e2eProviderConfigs/ethConsumer.yml +++ b/testutil/e2e/e2eProviderConfigs/ethConsumer.yml @@ -1,4 +1,4 @@ endpoints: - chain-id: ETH1 api-interface: jsonrpc - network-address: 127.0.0.1:3333 + network-address: 127.0.0.1:3331 From caf47ad9cb64885cde88efc5a1608910551780ab Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Sun, 2 Apr 2023 14:57:41 +0800 Subject: [PATCH 4/9] CNS-337: add testing of plan proposal and subscription Signed-off-by: Oren Laadan --- scripts/init_e2e.sh | 11 ++++++++++- testutil/e2e/README.md | 4 ++-- testutil/e2e/e2e.go | 42 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/scripts/init_e2e.sh b/scripts/init_e2e.sh index 5668b2d92b..d708a4c42d 100755 --- a/scripts/init_e2e.sh +++ b/scripts/init_e2e.sh @@ -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 @@ -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 \ No newline at end of file +sleep_until_next_epoch diff --git a/testutil/e2e/README.md b/testutil/e2e/README.md index 66642630b3..50d9a6a8dc 100644 --- a/testutil/e2e/README.md +++ b/testutil/e2e/README.md @@ -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. @@ -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. \ No newline at end of file +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. diff --git a/testutil/e2e/e2e.go b/testutil/e2e/e2e.go index 0825ab79c4..9f67c9022d 100644 --- a/testutil/e2e/e2e.go +++ b/testutil/e2e/e2e.go @@ -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" @@ -41,6 +42,7 @@ const ( ) var ( + checkedPlansE2E = []string{"DefaultPlan"} checkedSpecsE2E = []string{"LAV1", "ETH1"} checkedSpecsE2ELOL = []string{"GTH1"} ) @@ -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) @@ -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) { @@ -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") From 99b1d2e2af2cfcf1aef0ab48211e4c956111fa16 Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Sun, 2 Apr 2023 16:22:14 +0800 Subject: [PATCH 5/9] CNS-337: work with user3 too Add tests that for a client with active subscription ("user3"), similar to the tests with staked clients. --- cookbook/plans/default.json | 6 +- go.mod | 1 - go.sum | 2 - testutil/e2e/e2e.go | 77 ++++++++++++------- .../{ethConsumer.yml => ethConsumer1.yml} | 0 .../e2e/e2eProviderConfigs/ethConsumer2.yml | 4 + .../{lavaConsumer.yml => lavaConsumer1.yml} | 0 .../e2e/e2eProviderConfigs/lavaConsumer2.yml | 10 +++ 8 files changed, 65 insertions(+), 35 deletions(-) rename testutil/e2e/e2eProviderConfigs/{ethConsumer.yml => ethConsumer1.yml} (100%) create mode 100644 testutil/e2e/e2eProviderConfigs/ethConsumer2.yml rename testutil/e2e/e2eProviderConfigs/{lavaConsumer.yml => lavaConsumer1.yml} (100%) create mode 100644 testutil/e2e/e2eProviderConfigs/lavaConsumer2.yml diff --git a/cookbook/plans/default.json b/cookbook/plans/default.json index b0985e69ee..3d579f1df5 100755 --- a/cookbook/plans/default.json +++ b/cookbook/plans/default.json @@ -32,12 +32,12 @@ } ], "geolocation_profile": "18446744073709551615", - "total_cu_limit": "1000", - "epoch_cu_limit": "10", + "total_cu_limit": "1000000", + "epoch_cu_limit": "10000", "max_providers_to_pair": "3" } } ] }, "deposit": "10000000ulava" -} \ No newline at end of file +} diff --git a/go.mod b/go.mod index 4d86699ce4..802f0c16da 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,6 @@ require ( github.com/ghodss/yaml v1.0.0 // indirect github.com/gogo/googleapis v1.4.0 // indirect github.com/golang/glog v1.0.0 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect github.com/pelletier/go-toml/v2 v2.0.5 // indirect golang.org/x/mod v0.7.0 // indirect golang.org/x/tools v0.2.0 // indirect diff --git a/go.sum b/go.sum index 83ff3be0d1..8626d7221e 100644 --- a/go.sum +++ b/go.sum @@ -781,8 +781,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 h1:gDLXvp5S9izjldquuoAhDzccbskOL6tDC5jMSyx3zxE= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2/go.mod h1:7pdNwVWBBHGiCxa9lAszqCJMbfTISJ7oMftp8+UGV08= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= diff --git a/testutil/e2e/e2e.go b/testutil/e2e/e2e.go index 9f67c9022d..18b1ab4b83 100644 --- a/testutil/e2e/e2e.go +++ b/testutil/e2e/e2e.go @@ -282,13 +282,13 @@ func (lt *lavaTest) startJSONRPCProvider(ctx context.Context) { } func (lt *lavaTest) startJSONRPCConsumer(ctx context.Context) { - for i, u := range []string{"user1"} { + for idx, u := range []string{"user1", "user3"} { command := fmt.Sprintf( - "%s rpcconsumer %s/ethConsumer.yml --from %s %s", - lt.lavadPath, configFolder, u, lt.lavadArgs, + "%s rpcconsumer %s/ethConsumer%d.yml --from %s %s", + lt.lavadPath, configFolder, idx+1, u, lt.lavadArgs, ) - logName := "04_jsonConsumer_" + fmt.Sprintf("%02d", i+1) - funcName := fmt.Sprintf("startJSONRPCConsumer (consumer %02d)", i+1) + logName := "04_jsonConsumer_" + fmt.Sprintf("%02d", idx+1) + funcName := fmt.Sprintf("startJSONRPCConsumer (consumer %02d)", idx+1) lt.execCommand(ctx, funcName, logName, command, false) } utils.LavaFormatInfo("startJSONRPCConsumer OK") @@ -456,10 +456,10 @@ func (lt *lavaTest) startLavaProviders(ctx context.Context) { } func (lt *lavaTest) startLavaConsumer(ctx context.Context) { - for idx, u := range []string{"user2"} { + for idx, u := range []string{"user2", "user3"} { command := fmt.Sprintf( - "%s rpcconsumer %s/lavaConsumer.yml --from %s %s", - lt.lavadPath, configFolder, u, lt.lavadArgs, + "%s rpcconsumer %s/lavaConsumer%d.yml --from %s %s", + lt.lavadPath, configFolder, idx+1, u, lt.lavadArgs, ) logName := "06_RPCConsumer_" + fmt.Sprintf("%02d", idx+1) funcName := fmt.Sprintf("startRPCConsumer (consumer %02d)", idx+1) @@ -819,6 +819,9 @@ func runE2E() { utils.LavaFormatInfo("RUNNING TESTS") + // hereinafter: + // run each consumer test once for staked client and once for subscription client + // ETH1 flow jsonCTX, cancel := context.WithCancel(context.Background()) defer cancel() @@ -827,7 +830,8 @@ func runE2E() { lt.checkJSONRPCConsumer("http://127.0.0.1:1111", time.Minute*2, "JSONRPCProxy OK") // checks proxy. lt.startJSONRPCProvider(jsonCTX) lt.startJSONRPCConsumer(jsonCTX) - lt.checkJSONRPCConsumer("http://127.0.0.1:3331/1", time.Minute*2, "JSONRPCConsumer OK") + lt.checkJSONRPCConsumer("http://127.0.0.1:3331/1", time.Minute*2, "JSONRPCConsumer1 OK") + lt.checkJSONRPCConsumer("http://127.0.0.1:3332/1", time.Minute*2, "JSONRPCConsumer2 OK") // Lava Flow rpcCtx, cancel := context.WithCancel(context.Background()) @@ -835,48 +839,63 @@ func runE2E() { lt.startLavaProviders(rpcCtx) lt.startLavaConsumer(rpcCtx) + // staked client then with subscription lt.checkTendermintConsumer("http://127.0.0.1:3340/1", time.Second*30) lt.checkRESTConsumer("http://127.0.0.1:3341/1", time.Second*30) lt.checkGRPCConsumer("127.0.0.1:3342", time.Second*30) + lt.checkTendermintConsumer("http://127.0.0.1:3343/1", time.Second*30) + lt.checkRESTConsumer("http://127.0.0.1:3344/1", time.Second*30) + lt.checkGRPCConsumer("127.0.0.1:3345", time.Second*30) - jsonErr := jsonrpcTests("http://127.0.0.1:3331/1", time.Second*30) - if jsonErr != nil { + // staked client then with subscription + if jsonErr := jsonrpcTests("http://127.0.0.1:3331/1", time.Second*30); jsonErr != nil { + panic(jsonErr) + } + if jsonErr := jsonrpcTests("http://127.0.0.1:3332/1", time.Second*30); jsonErr != nil { panic(jsonErr) - } else { - utils.LavaFormatInfo("JSONRPC TEST OK") } + utils.LavaFormatInfo("JSONRPC TEST OK") - tendermintErr := tendermintTests("http://127.0.0.1:3340/1", time.Second*30) - if tendermintErr != nil { + // staked client then with subscription + if tendermintErr := tendermintTests("http://127.0.0.1:3340/1", time.Second*30); tendermintErr != nil { + panic(tendermintErr) + } + if tendermintErr := tendermintTests("http://127.0.0.1:3343/1", time.Second*30); tendermintErr != nil { panic(tendermintErr) - } else { - utils.LavaFormatInfo("TENDERMINTRPC TEST OK") } + utils.LavaFormatInfo("TENDERMINTRPC TEST OK") - tendermintURIErr := tendermintURITests("http://127.0.0.1:3340/1", time.Second*30) - if tendermintURIErr != nil { + // staked client then with subscription + if tendermintURIErr := tendermintURITests("http://127.0.0.1:3340/1", time.Second*30); tendermintURIErr != nil { panic(tendermintURIErr) - } else { - utils.LavaFormatInfo("TENDERMINTRPC URI TEST OK") } + if tendermintURIErr := tendermintURITests("http://127.0.0.1:3343/1", time.Second*30); tendermintURIErr != nil { + panic(tendermintURIErr) + } + utils.LavaFormatInfo("TENDERMINTRPC URI TEST OK") lt.lavaOverLava(rpcCtx) - restErr := restTests("http://127.0.0.1:3341/1", time.Second*30) - if restErr != nil { + // staked client then with subscription + if restErr := restTests("http://127.0.0.1:3341/1", time.Second*30); restErr != nil { + panic(restErr) + } + if restErr := restTests("http://127.0.0.1:3344/1", time.Second*30); restErr != nil { panic(restErr) - } else { - utils.LavaFormatInfo("REST TEST OK") } + utils.LavaFormatInfo("REST TEST OK") lt.checkPayments(time.Minute * 10) - grpcErr := grpcTests("127.0.0.1:3342", time.Second*5) // TODO: if set to 30 secs fails e2e need to investigate why. currently blocking PR's - if grpcErr != nil { + // staked client then with subscription + // TODO: if set to 30 secs fails e2e need to investigate why. currently blocking PR's + if grpcErr := grpcTests("127.0.0.1:3342", time.Second*5); grpcErr != nil { + panic(grpcErr) + } + if grpcErr := grpcTests("127.0.0.1:3345", time.Second*5); grpcErr != nil { panic(grpcErr) - } else { - utils.LavaFormatInfo("GRPC TEST OK") } + utils.LavaFormatInfo("GRPC TEST OK") jsonCTX.Done() rpcCtx.Done() diff --git a/testutil/e2e/e2eProviderConfigs/ethConsumer.yml b/testutil/e2e/e2eProviderConfigs/ethConsumer1.yml similarity index 100% rename from testutil/e2e/e2eProviderConfigs/ethConsumer.yml rename to testutil/e2e/e2eProviderConfigs/ethConsumer1.yml diff --git a/testutil/e2e/e2eProviderConfigs/ethConsumer2.yml b/testutil/e2e/e2eProviderConfigs/ethConsumer2.yml new file mode 100644 index 0000000000..70bd6b589d --- /dev/null +++ b/testutil/e2e/e2eProviderConfigs/ethConsumer2.yml @@ -0,0 +1,4 @@ +endpoints: + - chain-id: ETH1 + api-interface: jsonrpc + network-address: 127.0.0.1:3332 diff --git a/testutil/e2e/e2eProviderConfigs/lavaConsumer.yml b/testutil/e2e/e2eProviderConfigs/lavaConsumer1.yml similarity index 100% rename from testutil/e2e/e2eProviderConfigs/lavaConsumer.yml rename to testutil/e2e/e2eProviderConfigs/lavaConsumer1.yml diff --git a/testutil/e2e/e2eProviderConfigs/lavaConsumer2.yml b/testutil/e2e/e2eProviderConfigs/lavaConsumer2.yml new file mode 100644 index 0000000000..403b31c0fd --- /dev/null +++ b/testutil/e2e/e2eProviderConfigs/lavaConsumer2.yml @@ -0,0 +1,10 @@ +endpoints: + - chain-id: LAV1 + api-interface: tendermintrpc + network-address: 127.0.0.1:3343 + - chain-id: LAV1 + api-interface: rest + network-address: 127.0.0.1:3344 + - chain-id: LAV1 + api-interface: grpc + network-address: 127.0.0.1:3345 From b376274756cc82654d7b8910144af0f163816b7d Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Sun, 2 Apr 2023 16:36:55 +0800 Subject: [PATCH 6/9] CNS-337: sort out test timeout The e2e timeout was inconsistent: First, "go test" default timeout is 10 minutes, which it can be changed using "go test -timeout ...". However, the e2e test internally runs another "go test" without any argument, so even if the user specified a longer timeout for the test, the latter would fail within the default timeout. Second, in at least one place the timeout was hard-coded fixed to 10 minutes. This is fixed by settings the timeout the intenral "go test" to zero, and then insteead settings the context.WithTimeout to the timeout requested by the user. --- testutil/e2e/e2e.go | 30 +++++++++++++----------------- testutil/e2e/lava_fullFlow_test.go | 10 +++++++++- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/testutil/e2e/e2e.go b/testutil/e2e/e2e.go index 18b1ab4b83..2d75d37e86 100644 --- a/testutil/e2e/e2e.go +++ b/testutil/e2e/e2e.go @@ -254,7 +254,9 @@ func (lt *lavaTest) startJSONRPCProxy(ctx context.Context) { if err != nil { panic("Could not find go executable path") } - command := goExecutablePath + " test ./testutil/e2e/proxy/. -v eth" + // force go's test timeout to 0, otherwise the default is 10m; our timeout + // will be enforced by the given ctx. + command := goExecutablePath + " test ./testutil/e2e/proxy/. -v -timeout 0 eth" logName := "02_jsonProxy" funcName := "startJSONRPCProxy" @@ -775,7 +777,7 @@ func (lt *lavaTest) checkPayments(testDuration time.Duration) { } } -func runE2E() { +func runE2E(timeout time.Duration) { os.RemoveAll(logsFolder) gopath := os.Getenv("GOPATH") if gopath == "" { @@ -806,7 +808,7 @@ func runE2E() { utils.LavaFormatInfo("Starting Lava") go lt.startLava(context.Background()) - lt.checkLava(time.Minute * 10) + lt.checkLava(timeout) utils.LavaFormatInfo("Starting Lava OK") utils.LavaFormatInfo("Staking Lava") lt.stakeLava() @@ -822,23 +824,20 @@ func runE2E() { // hereinafter: // run each consumer test once for staked client and once for subscription client - // ETH1 flow - jsonCTX, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - lt.startJSONRPCProxy(jsonCTX) + // ETH1 flow + lt.startJSONRPCProxy(ctx) lt.checkJSONRPCConsumer("http://127.0.0.1:1111", time.Minute*2, "JSONRPCProxy OK") // checks proxy. - lt.startJSONRPCProvider(jsonCTX) - lt.startJSONRPCConsumer(jsonCTX) + lt.startJSONRPCProvider(ctx) + lt.startJSONRPCConsumer(ctx) lt.checkJSONRPCConsumer("http://127.0.0.1:3331/1", time.Minute*2, "JSONRPCConsumer1 OK") lt.checkJSONRPCConsumer("http://127.0.0.1:3332/1", time.Minute*2, "JSONRPCConsumer2 OK") // Lava Flow - rpcCtx, cancel := context.WithCancel(context.Background()) - defer cancel() - - lt.startLavaProviders(rpcCtx) - lt.startLavaConsumer(rpcCtx) + lt.startLavaProviders(ctx) + lt.startLavaConsumer(ctx) // staked client then with subscription lt.checkTendermintConsumer("http://127.0.0.1:3340/1", time.Second*30) lt.checkRESTConsumer("http://127.0.0.1:3341/1", time.Second*30) @@ -874,7 +873,7 @@ func runE2E() { } utils.LavaFormatInfo("TENDERMINTRPC URI TEST OK") - lt.lavaOverLava(rpcCtx) + lt.lavaOverLava(ctx) // staked client then with subscription if restErr := restTests("http://127.0.0.1:3341/1", time.Second*30); restErr != nil { @@ -897,8 +896,5 @@ func runE2E() { } utils.LavaFormatInfo("GRPC TEST OK") - jsonCTX.Done() - rpcCtx.Done() - lt.finishTestSuccessfully() } diff --git a/testutil/e2e/lava_fullFlow_test.go b/testutil/e2e/lava_fullFlow_test.go index 453a8b0593..995de8b1e8 100644 --- a/testutil/e2e/lava_fullFlow_test.go +++ b/testutil/e2e/lava_fullFlow_test.go @@ -2,8 +2,16 @@ package e2e import ( "testing" + "time" ) func TestLava(t *testing.T) { - runE2E() + // default timeout same as `go test` + timeout := time.Minute * 10 + + if deadline, ok := t.Deadline(); ok { + timeout = deadline.Sub(time.Now()).Round(10*time.Second) + } + + runE2E(timeout) } From bd1fa149943ae8ee08eac0e70e52ec7bcc209d91 Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Mon, 24 Apr 2023 15:53:19 +0800 Subject: [PATCH 7/9] CNS-337: [review] fix lint issues --- testutil/e2e/e2e.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testutil/e2e/e2e.go b/testutil/e2e/e2e.go index 2d75d37e86..feee8a3990 100644 --- a/testutil/e2e/e2e.go +++ b/testutil/e2e/e2e.go @@ -85,12 +85,12 @@ func (lt *lavaTest) execCommand(ctx context.Context, funcName string, logName st if wait { if err = cmd.Wait(); err != nil { - panic(funcName + " failed " + err.Error()) + panic(funcName + " failed " + err.Error()) } } else { lt.commands[logName] = cmd go func() { - lt.listenCmdCommand(cmd, funcName + " process returned unexpectedly", funcName) + lt.listenCmdCommand(cmd, funcName+" process returned unexpectedly", funcName) }() } } From a3a5dcc721a354a1d027cd864de5dd4fe87049da Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Mon, 1 May 2023 12:59:30 +0800 Subject: [PATCH 8/9] CNS-337: [review] fix default plan to include LAV1 --- cookbook/plans/default.json | 7 ++++++- protocol/lavasession/errors.go | 2 +- testutil/e2e/lava_fullFlow_test.go | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cookbook/plans/default.json b/cookbook/plans/default.json index 3d579f1df5..09fbd0c025 100755 --- a/cookbook/plans/default.json +++ b/cookbook/plans/default.json @@ -16,6 +16,11 @@ "overuse_rate": "0", "plan_policy": { "chain_policies": [ + { + "chain_id": "LAV1", + "apis": [ + ] + }, { "chain_id": "ETH1", "apis": [ @@ -33,7 +38,7 @@ ], "geolocation_profile": "18446744073709551615", "total_cu_limit": "1000000", - "epoch_cu_limit": "10000", + "epoch_cu_limit": "20000", "max_providers_to_pair": "3" } } diff --git a/protocol/lavasession/errors.go b/protocol/lavasession/errors.go index ab20f932e5..8821c72bdd 100644 --- a/protocol/lavasession/errors.go +++ b/protocol/lavasession/errors.go @@ -9,7 +9,7 @@ var ( // Consumer Side Errors UnreachableCodeError = sdkerrors.New("UnreachableCode Error", 666, "Should not get here.") AllProviderEndpointsDisabledError = sdkerrors.New("AllProviderEndpointsDisabled Error", 667, "All endpoints are not available.") // a provider is completely unresponsive all endpoints are not available MaximumNumberOfSessionsExceededError = sdkerrors.New("MaximumNumberOfSessionsExceeded Error", 668, "Provider reached maximum number of active sessions.") - MaxComputeUnitsExceededError = sdkerrors.New("MaxComputeUnitsExceeded Error", 669, "Consumer is trying to exceed the maximum number of compute uints available.") + MaxComputeUnitsExceededError = sdkerrors.New("MaxComputeUnitsExceeded Error", 669, "Consumer is trying to exceed the maximum number of compute units available.") EpochMismatchError = sdkerrors.New("ReportingAnOldEpoch Error", 670, "Tried to Report to an older epoch") AddressIndexWasNotFoundError = sdkerrors.New("AddressIndexWasNotFound Error", 671, "address index was not found in list") LockMisUseDetectedError = sdkerrors.New("LockMisUseDetected Error", 672, "Faulty use of locks detected") diff --git a/testutil/e2e/lava_fullFlow_test.go b/testutil/e2e/lava_fullFlow_test.go index 995de8b1e8..2d4fe5fbb0 100644 --- a/testutil/e2e/lava_fullFlow_test.go +++ b/testutil/e2e/lava_fullFlow_test.go @@ -10,7 +10,7 @@ func TestLava(t *testing.T) { timeout := time.Minute * 10 if deadline, ok := t.Deadline(); ok { - timeout = deadline.Sub(time.Now()).Round(10*time.Second) + timeout = time.Until(deadline).Round(10 * time.Second) } runE2E(timeout) From 223e74c4227eecbbc0aa86c6c31ee26ec495064d Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Mon, 1 May 2023 20:57:18 +0800 Subject: [PATCH 9/9] CNS-337: reduce test time by removing redundant client tests Initially subscription testing was added on top of staked clients, so it doubled the (already long) test time. However, it's enough to test staked-clients on ETH1 and subscriptions on LAV1, as it still provides full coverage of the core functionalty (while each tests different access methods). Also generalize the code that invokes client tests so that it can handle multiple clients (currently up to 3, although we use only 1). --- .github/workflows/e2e.yml | 10 ++-- scripts/init_e2e.sh | 4 ++ testutil/e2e/e2e.go | 105 ++++++++++++++++++++++---------------- 3 files changed, 70 insertions(+), 49 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 7ff906ca51..cf922b9080 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -96,12 +96,12 @@ jobs: - name: JSON Consumer All Logs if: always() - run: cat testutil/e2e/logs/04_jsonConsumer.log + run: grep "" testutil/e2e/logs/04_jsonConsumer* --exclude="*errors*" - name: JSON Consumer Error Only Logs if: always() continue-on-error: true - run: cat testutil/e2e/logs/04_jsonConsumer_errors.log + run: grep "" testutil/e2e/logs/04_jsonConsumer* --include="*errors*" - name: Lava Provider All Logs if: always() @@ -123,11 +123,9 @@ jobs: - name: RPCConsumer Consumer All Logs if: always() - run: cat testutil/e2e/logs/06_RPCConsumer.log + run: grep "" testutil/e2e/logs/06_RPCConsumer* --exclude="*errors*" - name: RPCConsumer Consumer Error Only Logs if: always() continue-on-error: true - run: cat testutil/e2e/logs/06_RPCConsumer_errors.log - - \ No newline at end of file + run: grep "" testutil/e2e/logs/06_RPCConsumer* --include="*errors*" diff --git a/scripts/init_e2e.sh b/scripts/init_e2e.sh index d708a4c42d..019b65586b 100755 --- a/scripts/init_e2e.sh +++ b/scripts/init_e2e.sh @@ -29,6 +29,10 @@ lavad tx pairing stake-provider "LAV1" $STAKE "127.0.0.1:2263,tendermintrpc,1 12 lavad tx pairing stake-provider "LAV1" $STAKE "127.0.0.1:2264,tendermintrpc,1 127.0.0.1:2274,rest,1 127.0.0.1:2284,grpc,1" 1 -y --from servicer9 --provider-moniker "dummyMoniker" --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE lavad tx pairing stake-provider "LAV1" $STAKE "127.0.0.1:2265,tendermintrpc,1 127.0.0.1:2275,rest,1 127.0.0.1:2285,grpc,1" 1 -y --from servicer10 --provider-moniker "dummyMoniker" --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE +# staked clients +# (actually, only user1 is used in testutils/e2e/e2e.go, but having same count +# in both chains simplifies the e2e logic that expects same amount of staked +# clients in all tested chains) 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 diff --git a/testutil/e2e/e2e.go b/testutil/e2e/e2e.go index feee8a3990..f08b38b018 100644 --- a/testutil/e2e/e2e.go +++ b/testutil/e2e/e2e.go @@ -284,7 +284,7 @@ func (lt *lavaTest) startJSONRPCProvider(ctx context.Context) { } func (lt *lavaTest) startJSONRPCConsumer(ctx context.Context) { - for idx, u := range []string{"user1", "user3"} { + for idx, u := range []string{"user1"} { command := fmt.Sprintf( "%s rpcconsumer %s/ethConsumer%d.yml --from %s %s", lt.lavadPath, configFolder, idx+1, u, lt.lavadArgs, @@ -458,7 +458,7 @@ func (lt *lavaTest) startLavaProviders(ctx context.Context) { } func (lt *lavaTest) startLavaConsumer(ctx context.Context) { - for idx, u := range []string{"user2", "user3"} { + for idx, u := range []string{"user3"} { command := fmt.Sprintf( "%s rpcconsumer %s/lavaConsumer%d.yml --from %s %s", lt.lavadPath, configFolder, idx+1, u, lt.lavadArgs, @@ -632,17 +632,18 @@ func (lt *lavaTest) checkGRPCConsumer(rpcURL string, timeout time.Duration) { func grpcTests(rpcURL string, testDuration time.Duration) error { ctx := context.Background() utils.LavaFormatInfo("Starting GRPC Tests") - errors := []string{} grpcConn, err := grpc.Dial(rpcURL, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - errors = append(errors, "error client dial") + return fmt.Errorf("error client dial: %s", err.Error()) } + errors := []string{} specQueryClient := specTypes.NewQueryClient(grpcConn) pairingQueryClient := pairingTypes.NewQueryClient(grpcConn) for start := time.Now(); time.Since(start) < testDuration; { specQueryRes, err := specQueryClient.SpecAll(ctx, &specTypes.QueryAllSpecRequest{}) if err != nil { errors = append(errors, err.Error()) + continue } for _, spec := range specQueryRes.Spec { _, err = pairingQueryClient.Providers(context.Background(), &pairingTypes.QueryProvidersRequest{ @@ -816,13 +817,24 @@ func runE2E(timeout time.Duration) { // scripts/init_e2e.sh will: // - produce 4 specs: ETH1, GTH1, IBC, COSMOSSDK, LAV1 (via spec_add_{ethereum,cosmoshub,lava}) // - produce 1 plan: "DefaultPlan" + // - produce 5 staked providers (for each of ETH1, LAV1) + // - produce 1 staked client (for each of ETH1, LAV1) + // - produce 1 subscription (for both ETH1, LAV1) lt.checkStakeLava(1, 5, 5, 1, checkedPlansE2E, checkedSpecsE2E, "Staking Lava OK") utils.LavaFormatInfo("RUNNING TESTS") // hereinafter: - // run each consumer test once for staked client and once for subscription client + // run each consumer test once for each client/user (staked or subscription) + + // repeat() is a helper to run a given function once per client, passing the + // iteration (client) number to the function + repeat := func(n int, f func(int)) { + for i := 1; i <= n; i++ { + f(i) + } + } ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -832,68 +844,75 @@ func runE2E(timeout time.Duration) { lt.checkJSONRPCConsumer("http://127.0.0.1:1111", time.Minute*2, "JSONRPCProxy OK") // checks proxy. lt.startJSONRPCProvider(ctx) lt.startJSONRPCConsumer(ctx) - lt.checkJSONRPCConsumer("http://127.0.0.1:3331/1", time.Minute*2, "JSONRPCConsumer1 OK") - lt.checkJSONRPCConsumer("http://127.0.0.1:3332/1", time.Minute*2, "JSONRPCConsumer2 OK") + + repeat(1, func(n int) { + url := fmt.Sprintf("http://127.0.0.1:333%d/1", n) + msg := fmt.Sprintf("JSONRPCConsumer%d OK", n) + lt.checkJSONRPCConsumer(url, time.Minute*2, msg) + }) // Lava Flow lt.startLavaProviders(ctx) lt.startLavaConsumer(ctx) + // staked client then with subscription - lt.checkTendermintConsumer("http://127.0.0.1:3340/1", time.Second*30) - lt.checkRESTConsumer("http://127.0.0.1:3341/1", time.Second*30) - lt.checkGRPCConsumer("127.0.0.1:3342", time.Second*30) - lt.checkTendermintConsumer("http://127.0.0.1:3343/1", time.Second*30) - lt.checkRESTConsumer("http://127.0.0.1:3344/1", time.Second*30) - lt.checkGRPCConsumer("127.0.0.1:3345", time.Second*30) + repeat(1, func(n int) { + url := fmt.Sprintf("http://127.0.0.1:334%d/1", (n-1)*3) + lt.checkTendermintConsumer(url, time.Second*30) + url = fmt.Sprintf("http://127.0.0.1:334%d/1", (n-1)*3+1) + lt.checkRESTConsumer(url, time.Second*30) + url = fmt.Sprintf("127.0.0.1:334%d", (n-1)*3+2) + lt.checkGRPCConsumer(url, time.Second*30) + }) // staked client then with subscription - if jsonErr := jsonrpcTests("http://127.0.0.1:3331/1", time.Second*30); jsonErr != nil { - panic(jsonErr) - } - if jsonErr := jsonrpcTests("http://127.0.0.1:3332/1", time.Second*30); jsonErr != nil { - panic(jsonErr) - } + repeat(1, func(n int) { + url := fmt.Sprintf("http://127.0.0.1:333%d/1", n) + if err := jsonrpcTests(url, time.Second*30); err != nil { + panic(err) + } + }) utils.LavaFormatInfo("JSONRPC TEST OK") // staked client then with subscription - if tendermintErr := tendermintTests("http://127.0.0.1:3340/1", time.Second*30); tendermintErr != nil { - panic(tendermintErr) - } - if tendermintErr := tendermintTests("http://127.0.0.1:3343/1", time.Second*30); tendermintErr != nil { - panic(tendermintErr) - } + repeat(1, func(n int) { + url := fmt.Sprintf("http://127.0.0.1:334%d/1", (n-1)*3) + if err := tendermintTests(url, time.Second*30); err != nil { + panic(err) + } + }) utils.LavaFormatInfo("TENDERMINTRPC TEST OK") // staked client then with subscription - if tendermintURIErr := tendermintURITests("http://127.0.0.1:3340/1", time.Second*30); tendermintURIErr != nil { - panic(tendermintURIErr) - } - if tendermintURIErr := tendermintURITests("http://127.0.0.1:3343/1", time.Second*30); tendermintURIErr != nil { - panic(tendermintURIErr) - } + repeat(1, func(n int) { + url := fmt.Sprintf("http://127.0.0.1:334%d/1", (n-1)*3) + if err := tendermintURITests(url, time.Second*30); err != nil { + panic(err) + } + }) utils.LavaFormatInfo("TENDERMINTRPC URI TEST OK") lt.lavaOverLava(ctx) // staked client then with subscription - if restErr := restTests("http://127.0.0.1:3341/1", time.Second*30); restErr != nil { - panic(restErr) - } - if restErr := restTests("http://127.0.0.1:3344/1", time.Second*30); restErr != nil { - panic(restErr) - } + repeat(1, func(n int) { + url := fmt.Sprintf("http://127.0.0.1:334%d/1", (n-1)*3+1) + if err := restTests(url, time.Second*30); err != nil { + panic(err) + } + }) utils.LavaFormatInfo("REST TEST OK") lt.checkPayments(time.Minute * 10) // staked client then with subscription // TODO: if set to 30 secs fails e2e need to investigate why. currently blocking PR's - if grpcErr := grpcTests("127.0.0.1:3342", time.Second*5); grpcErr != nil { - panic(grpcErr) - } - if grpcErr := grpcTests("127.0.0.1:3345", time.Second*5); grpcErr != nil { - panic(grpcErr) - } + repeat(1, func(n int) { + url := fmt.Sprintf("127.0.0.1:334%d", (n-1)*3+2) + if err := grpcTests(url, time.Second*5); err != nil { + panic(err) + } + }) utils.LavaFormatInfo("GRPC TEST OK") lt.finishTestSuccessfully()