From 335b473408c74391d3dadc0c52fe12ee3760c601 Mon Sep 17 00:00:00 2001 From: Sasa-Ethernal Date: Fri, 24 May 2024 15:05:40 +0200 Subject: [PATCH] testfix --- Makefile | 4 +- e2e-polybft/cardanofw/test-apex-user.go | 2 +- e2e-polybft/e2e/apex_bridge_test.go | 165 ++++++++++++------------ 3 files changed, 85 insertions(+), 86 deletions(-) diff --git a/Makefile b/Makefile index 8e5624b015..398484fc60 100644 --- a/Makefile +++ b/Makefile @@ -77,13 +77,13 @@ test-e2e-legacy: check-go test-e2e-polybft: check-go go build -o artifacts/blade . env EDGE_BINARY=${PWD}/artifacts/blade E2E_TESTS=true E2E_LOGS=true \ - go test -v -timeout=1h30m ./e2e-polybft/e2e/... + go test -v -timeout=5h ./e2e-polybft/e2e/... .PHONY: test-e2e-apex-bridge test-e2e-apex-bridge: check-go go build -o artifacts/blade . env EDGE_BINARY=${PWD}/artifacts/blade E2E_TESTS=true E2E_LOGS=true \ - go test -v -timeout=1h30m ./e2e-polybft/e2e/... -run "ApexBridge" + go test -v -timeout=5h ./e2e-polybft/e2e/... -run "ApexBridge" .PHONY: test-property-polybft test-property-polybft: check-go diff --git a/e2e-polybft/cardanofw/test-apex-user.go b/e2e-polybft/cardanofw/test-apex-user.go index 9592fb8aba..f1056ad8e1 100644 --- a/e2e-polybft/cardanofw/test-apex-user.go +++ b/e2e-polybft/cardanofw/test-apex-user.go @@ -182,7 +182,7 @@ func BridgeAmountFull( ) string { t.Helper() - const feeAmount = 1_100_000 + const feeAmount = 2_000_000 senderAddr, _, err := wallet.GetWalletAddress(sender, networkMagic) require.NoError(t, err) diff --git a/e2e-polybft/e2e/apex_bridge_test.go b/e2e-polybft/e2e/apex_bridge_test.go index d5f1542622..fa65bddcd2 100644 --- a/e2e-polybft/e2e/apex_bridge_test.go +++ b/e2e-polybft/e2e/apex_bridge_test.go @@ -701,6 +701,7 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { fmt.Printf("prevAmount: %v. newAmount: %v\n", prevAmount, newAmount) }) + //nolint:dupl t.Run("From prime to vector 200x 5min 90%", func(t *testing.T) { instances := 200 maxWaitTime := 300 @@ -716,6 +717,10 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { fmt.Printf("Funding %v Wallets\n", instances) for i := 0; i < instances; i++ { + if (i+1)%100 == 0 { + fmt.Printf("Funded %v..%v\n", i-99, i) + } + walletKeys[i], err = wallet.NewStakeWalletManager().Create(path.Join(apex.PrimeCluster.Config.Dir("keys")), true) require.NoError(t, err) @@ -728,7 +733,6 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { fmt.Printf("Funding Complete\n") var wg sync.WaitGroup - //nolint:dupl for i := 0; i < instances; i++ { wg.Add(1) @@ -736,17 +740,13 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { defer wg.Done() if successChance > rand.Intn(100) { + succeededCount++ sleepTime := rand.Intn(maxWaitTime) time.Sleep(time.Second * time.Duration(sleepTime)) - txHash := cardanofw.BridgeAmountFull(t, ctx, txProviderPrime, uint(apex.PrimeCluster.Config.NetworkMagic), + cardanofw.BridgeAmountFull(t, ctx, txProviderPrime, uint(apex.PrimeCluster.Config.NetworkMagic), apex.Bridge.PrimeMultisigAddr, apex.Bridge.VectorMultisigFeeAddr, walletKeys[idx], user.VectorAddress, sendAmount, cardanofw.GetDestinationChainID(true)) - succeededCount++ - - err = wallet.WaitForTxHashInUtxos(ctx, txProviderVector, user.VectorAddress, txHash, 12, time.Second*10) - require.NoError(t, err) - fmt.Printf("Tx %v sent. hash: %s\n", idx+1, txHash) } else { feeAmount := uint64(1_100_000) receivers := map[string]uint64{ @@ -758,38 +758,40 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { user.PrimeAddress, receivers, cardanofw.GetDestinationChainID(true)) require.NoError(t, err) - txHash, err := cardanofw.SendTx( + _, err = cardanofw.SendTx( ctx, txProviderPrime, walletKeys[idx], (sendAmount + feeAmount), apex.Bridge.PrimeMultisigAddr, apex.PrimeCluster.Config.NetworkMagic, bridgingRequestMetadata) require.NoError(t, err) - - apiURL, err := apex.Bridge.GetBridgingAPI() - require.NoError(t, err) - cardanofw.WaitForInvalidState(t, ctx, apiURL, apiKey, txHash) - fmt.Printf("Tx %v invalid. hash: %s\n", idx+1, txHash) } }(i) } wg.Wait() + fmt.Printf("All tx sent, waiting for confirmation.\n") + expectedAmount := prevAmount.Uint64() + uint64(succeededCount)*sendAmount - err = wallet.WaitForAmount(context.Background(), txProviderVector, user.VectorAddress, func(val *big.Int) bool { - return val.Cmp(new(big.Int).SetUint64(expectedAmount)) == 0 - }, 100, time.Second*10) - require.NoError(t, err) - fmt.Printf("%v TXs confirmed\n", succeededCount) + var newAmount *big.Int + for i := 0; i < instances; i++ { + newAmount, err = cardanofw.GetTokenAmount(ctx, txProviderVector, user.VectorAddress) + require.NoError(t, err) + fmt.Printf("Current Amount Prime: %v. Expected: %v\n", newAmount, expectedAmount) - newAmount, err := cardanofw.GetTokenAmount(ctx, txProviderVector, user.VectorAddress) - require.NoError(t, err) + if newAmount.Uint64() == expectedAmount { + break + } - fmt.Printf("prevAmount: %v. newAmount: %v\n", prevAmount, newAmount) + time.Sleep(time.Second * 10) + } + + fmt.Printf("Success count: %v. prevAmount: %v. newAmount: %v. expectedAmount: %v\n", succeededCount, prevAmount, newAmount, expectedAmount) }) - t.Run("From prime to vector 1000x 30sec 90%", func(t *testing.T) { + //nolint:dupl + t.Run("From prime to vector 1000x 20min 90%", func(t *testing.T) { instances := 1000 - maxWaitTime := 30 + maxWaitTime := 1200 fundSendAmount := uint64(5_000_000) sendAmount := uint64(1_000_000) successChance := 90 // 90% @@ -802,6 +804,10 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { fmt.Printf("Funding %v Wallets\n", instances) for i := 0; i < instances; i++ { + if (i+1)%100 == 0 { + fmt.Printf("Funded %v..%v\n", i-99, i) + } + walletKeys[i], err = wallet.NewStakeWalletManager().Create(path.Join(apex.PrimeCluster.Config.Dir("keys")), true) require.NoError(t, err) @@ -814,7 +820,6 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { fmt.Printf("Funding Complete\n") var wg sync.WaitGroup - //nolint:dupl for i := 0; i < instances; i++ { wg.Add(1) @@ -822,17 +827,13 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { defer wg.Done() if successChance > rand.Intn(100) { + succeededCount++ sleepTime := rand.Intn(maxWaitTime) time.Sleep(time.Second * time.Duration(sleepTime)) - txHash := cardanofw.BridgeAmountFull(t, ctx, txProviderPrime, uint(apex.PrimeCluster.Config.NetworkMagic), + cardanofw.BridgeAmountFull(t, ctx, txProviderPrime, uint(apex.PrimeCluster.Config.NetworkMagic), apex.Bridge.PrimeMultisigAddr, apex.Bridge.VectorMultisigFeeAddr, walletKeys[idx], user.VectorAddress, sendAmount, cardanofw.GetDestinationChainID(true)) - succeededCount++ - - err = wallet.WaitForTxHashInUtxos(ctx, txProviderVector, user.VectorAddress, txHash, 12, time.Second*10) - require.NoError(t, err) - fmt.Printf("Tx %v sent. hash: %s\n", idx+1, txHash) } else { feeAmount := uint64(1_100_000) receivers := map[string]uint64{ @@ -844,38 +845,39 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { user.PrimeAddress, receivers, cardanofw.GetDestinationChainID(true)) require.NoError(t, err) - txHash, err := cardanofw.SendTx( + _, err = cardanofw.SendTx( ctx, txProviderPrime, walletKeys[idx], (sendAmount + feeAmount), apex.Bridge.PrimeMultisigAddr, apex.PrimeCluster.Config.NetworkMagic, bridgingRequestMetadata) require.NoError(t, err) - - apiURL, err := apex.Bridge.GetBridgingAPI() - require.NoError(t, err) - cardanofw.WaitForInvalidState(t, ctx, apiURL, apiKey, txHash) - fmt.Printf("Tx %v invalid. hash: %s\n", idx+1, txHash) } }(i) } wg.Wait() + fmt.Printf("All tx sent, waiting for confirmation.\n") + expectedAmount := prevAmount.Uint64() + uint64(succeededCount)*sendAmount - err = wallet.WaitForAmount(context.Background(), txProviderVector, user.VectorAddress, func(val *big.Int) bool { - return val.Cmp(new(big.Int).SetUint64(expectedAmount)) == 0 - }, 100, time.Second*10) - require.NoError(t, err) - fmt.Printf("%v TXs confirmed\n", succeededCount) + var newAmount *big.Int + for i := 0; i < instances; i++ { + newAmount, err = cardanofw.GetTokenAmount(ctx, txProviderVector, user.VectorAddress) + require.NoError(t, err) + fmt.Printf("Current Amount Prime: %v. Expected: %v\n", newAmount, expectedAmount) + + if newAmount.Uint64() == expectedAmount { + break + } - newAmount, err := cardanofw.GetTokenAmount(ctx, txProviderVector, user.VectorAddress) - require.NoError(t, err) + time.Sleep(time.Second * 10) + } - fmt.Printf("prevAmount: %v. newAmount: %v. expectedAmount: %v\n", prevAmount, newAmount, expectedAmount) + fmt.Printf("Success count: %v. prevAmount: %v. newAmount: %v. expectedAmount: %v\n", succeededCount, prevAmount, newAmount.Uint64(), expectedAmount) }) - t.Run("Both directions 1000x 30sec 90%", func(t *testing.T) { + t.Run("Both directions 1000x 60min 90%", func(t *testing.T) { instances := 1000 - maxWaitTime := 30 + maxWaitTime := 3600 fundSendAmount := uint64(5_000_000) sendAmount := uint64(1_000_000) successChance := 90 // 90% @@ -892,6 +894,10 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { fmt.Printf("Funding %v Wallets\n", instances) for i := 0; i < instances; i++ { + if (i+1)%100 == 0 { + fmt.Printf("Funded %v..%v on prime\n", i-99, i) + } + walletKeysPrime[i], err = wallet.NewStakeWalletManager().Create(path.Join(apex.PrimeCluster.Config.Dir("keys")), true) require.NoError(t, err) @@ -902,6 +908,10 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { } for i := 0; i < instances; i++ { + if (i+1)%100 == 0 { + fmt.Printf("Funded %v..%v on vector\n", i-99, i) + } + walletKeysVector[i], err = wallet.NewStakeWalletManager().Create(path.Join(apex.VectorCluster.Config.Dir("keys")), true) require.NoError(t, err) @@ -922,17 +932,13 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { defer wg.Done() if successChance > rand.Intn(100) { + succeededCountPrime++ sleepTime := rand.Intn(maxWaitTime) time.Sleep(time.Second * time.Duration(sleepTime)) - txHash := cardanofw.BridgeAmountFull(t, ctx, txProviderPrime, uint(apex.PrimeCluster.Config.NetworkMagic), + cardanofw.BridgeAmountFull(t, ctx, txProviderPrime, uint(apex.PrimeCluster.Config.NetworkMagic), apex.Bridge.PrimeMultisigAddr, apex.Bridge.VectorMultisigFeeAddr, walletKeysPrime[idx], user.VectorAddress, sendAmount, cardanofw.GetDestinationChainID(true)) - succeededCountPrime++ - - err = wallet.WaitForTxHashInUtxos(ctx, txProviderVector, user.VectorAddress, txHash, 12, time.Second*10) - require.NoError(t, err) - fmt.Printf("Prime Tx %v sent. hash: %s\n", idx+1, txHash) } else { feeAmount := uint64(1_100_000) receivers := map[string]uint64{ @@ -944,15 +950,10 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { user.PrimeAddress, receivers, cardanofw.GetDestinationChainID(true)) require.NoError(t, err) - txHash, err := cardanofw.SendTx( + _, err = cardanofw.SendTx( ctx, txProviderPrime, walletKeysPrime[idx], (sendAmount + feeAmount), apex.Bridge.PrimeMultisigAddr, apex.PrimeCluster.Config.NetworkMagic, bridgingRequestMetadata) require.NoError(t, err) - - apiURL, err := apex.Bridge.GetBridgingAPI() - require.NoError(t, err) - cardanofw.WaitForInvalidState(t, ctx, apiURL, apiKey, txHash) - fmt.Printf("Prime Tx %v invalid. hash: %s\n", idx+1, txHash) } }(i) @@ -961,17 +962,13 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { defer wg.Done() if successChance > rand.Intn(100) { + succeededCountVector++ sleepTime := rand.Intn(maxWaitTime) time.Sleep(time.Second * time.Duration(sleepTime)) - txHash := cardanofw.BridgeAmountFull(t, ctx, txProviderVector, uint(apex.VectorCluster.Config.NetworkMagic), + cardanofw.BridgeAmountFull(t, ctx, txProviderVector, uint(apex.VectorCluster.Config.NetworkMagic), apex.Bridge.VectorMultisigAddr, apex.Bridge.PrimeMultisigFeeAddr, walletKeysVector[idx], user.PrimeAddress, sendAmount, cardanofw.GetDestinationChainID(false)) - succeededCountVector++ - - err = wallet.WaitForTxHashInUtxos(ctx, txProviderVector, user.PrimeAddress, txHash, 12, time.Second*10) - require.NoError(t, err) - fmt.Printf("Vector Tx %v sent. hash: %s\n", idx+1, txHash) } else { feeAmount := uint64(1_100_000) receivers := map[string]uint64{ @@ -983,42 +980,44 @@ func TestE2E_ApexBridge_ValidScenarios(t *testing.T) { user.VectorAddress, receivers, cardanofw.GetDestinationChainID(false)) require.NoError(t, err) - txHash, err := cardanofw.SendTx( + _, err = cardanofw.SendTx( ctx, txProviderVector, walletKeysVector[idx], (sendAmount + feeAmount), apex.Bridge.VectorMultisigAddr, apex.VectorCluster.Config.NetworkMagic, bridgingRequestMetadata) require.NoError(t, err) - - apiURL, err := apex.Bridge.GetBridgingAPI() - require.NoError(t, err) - cardanofw.WaitForInvalidState(t, ctx, apiURL, apiKey, txHash) - fmt.Printf("Tx %v invalid. hash: %s\n", idx+1, txHash) } }(i) } wg.Wait() - expectedAmountPrime := prevAmountPrime.Uint64() + uint64(succeededCountPrime)*sendAmount - err = wallet.WaitForAmount(context.Background(), txProviderVector, user.VectorAddress, func(val *big.Int) bool { - return val.Cmp(new(big.Int).SetUint64(expectedAmountPrime)) == 0 - }, 100, time.Second*10) - require.NoError(t, err) - fmt.Printf("%v TXs confirmed on Prime\n", succeededCountPrime) + fmt.Printf("All tx sent, waiting for confirmation.\n") + expectedAmountPrime := prevAmountPrime.Uint64() + uint64(succeededCountPrime)*sendAmount expectedAmountVector := prevAmountVector.Uint64() + uint64(succeededCountVector)*sendAmount - err = wallet.WaitForAmount(context.Background(), txProviderPrime, user.PrimeAddress, func(val *big.Int) bool { - return val.Cmp(new(big.Int).SetUint64(expectedAmountVector)) == 0 - }, 100, time.Second*10) - require.NoError(t, err) - fmt.Printf("%v TXs confirmed on Vector\n", succeededCountVector) + + for i := 0; i < instances; i++ { + newAmountPrime, err := cardanofw.GetTokenAmount(ctx, txProviderVector, user.VectorAddress) + require.NoError(t, err) + fmt.Printf("Current Amount Prime: %v. Expected: %v\n", newAmountPrime, expectedAmountPrime) + + newAmountVector, err := cardanofw.GetTokenAmount(ctx, txProviderPrime, user.PrimeAddress) + require.NoError(t, err) + fmt.Printf("Current Amount Vector: %v. Expected: %v\n", newAmountVector, expectedAmountVector) + + if newAmountPrime.Uint64() == expectedAmountPrime && newAmountVector.Uint64() == expectedAmountVector { + break + } + + time.Sleep(time.Second * 10) + } newAmountPrime, err := cardanofw.GetTokenAmount(ctx, txProviderVector, user.VectorAddress) require.NoError(t, err) - fmt.Printf("prevAmount: %v. newAmount: %v. expectedAmount: %v\n", prevAmountPrime, newAmountPrime, expectedAmountPrime) + fmt.Printf("Success count: %v. prevAmount: %v. newAmount: %v. expectedAmount: %v\n", succeededCountPrime, prevAmountPrime, newAmountPrime, expectedAmountPrime) newAmountVector, err := cardanofw.GetTokenAmount(ctx, txProviderPrime, user.PrimeAddress) require.NoError(t, err) - fmt.Printf("prevAmount: %v. newAmount: %v. expectedAmount: %v\n", prevAmountVector, newAmountVector, expectedAmountVector) + fmt.Printf("Success count: %v. prevAmount: %v. newAmount: %v. expectedAmount: %v\n", succeededCountVector, prevAmountVector, newAmountVector, expectedAmountVector) }) t.Run("Both directions sequential", func(t *testing.T) {