Skip to content

Commit

Permalink
testfix
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa-ethernal committed Jun 11, 2024
1 parent 57eb8b7 commit 335b473
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 86 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion e2e-polybft/cardanofw/test-apex-user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
165 changes: 82 additions & 83 deletions e2e-polybft/e2e/apex_bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -728,25 +733,20 @@ 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)

go func(idx int) {
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{
Expand All @@ -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
}

Check failure on line 784 in e2e-polybft/e2e/apex_bridge_test.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

undefined: wallet.GetWalletAddress

Check failure on line 784 in e2e-polybft/e2e/apex_bridge_test.go

View workflow job for this annotation

GitHub Actions / E2E ApexBridge Tests / Run E2E ApexBridge Tests

undefined: wallet.GetWalletAddress
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%
Expand All @@ -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)

Expand All @@ -814,25 +820,20 @@ 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)

go func(idx int) {
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{
Expand All @@ -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
}

Check failure on line 871 in e2e-polybft/e2e/apex_bridge_test.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

undefined: wallet.GetWalletAddress

Check failure on line 871 in e2e-polybft/e2e/apex_bridge_test.go

View workflow job for this annotation

GitHub Actions / E2E ApexBridge Tests / Run E2E ApexBridge Tests

undefined: wallet.GetWalletAddress
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%
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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{
Expand All @@ -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)

Expand All @@ -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{
Expand All @@ -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) {
Expand Down

0 comments on commit 335b473

Please sign in to comment.