Skip to content

Commit

Permalink
e2e: Switch assertion library from gomega to testify
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Sep 5, 2023
1 parent c3e9c83 commit 47997cf
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 75 deletions.
14 changes: 8 additions & 6 deletions tests/e2e/banff/suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package banff
import (
ginkgo "github.com/onsi/ginkgo/v2"

"github.com/onsi/gomega"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
Expand All @@ -20,6 +20,8 @@ import (
)

var _ = ginkgo.Describe("[Banff]", func() {
require := require.New(ginkgo.GinkgoT())

ginkgo.It("can send custom assets X->P and P->X",
// use this for filtering tests by labels
// ref. https://onsi.github.io/ginkgo/#spec-labels
Expand Down Expand Up @@ -59,7 +61,7 @@ var _ = ginkgo.Describe("[Banff]", func() {
},
},
)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
assetID = assetTx.ID()

tests.Outf("{{green}}created new X-chain asset{{/}}: %s\n", assetID)
Expand All @@ -80,14 +82,14 @@ var _ = ginkgo.Describe("[Banff]", func() {
},
},
)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

tests.Outf("{{green}}issued X-chain export{{/}}: %s\n", tx.ID())
})

ginkgo.By("import new asset from X-chain on the P-chain", func() {
tx, err := pWallet.IssueImportTx(xChainID, owner)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

tests.Outf("{{green}}issued P-chain import{{/}}: %s\n", tx.ID())
})
Expand All @@ -107,14 +109,14 @@ var _ = ginkgo.Describe("[Banff]", func() {
},
},
)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

tests.Outf("{{green}}issued P-chain export{{/}}: %s\n", tx.ID())
})

ginkgo.By("import asset from P-chain on the X-chain", func() {
tx, err := xWallet.IssueImportTx(constants.PlatformChainID, owner)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

tests.Outf("{{green}}issued X-chain import{{/}}: %s\n", tx.ID())
})
Expand Down
22 changes: 12 additions & 10 deletions tests/e2e/p/permissionless_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

ginkgo "github.com/onsi/ginkgo/v2"

"github.com/onsi/gomega"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/e2e"
Expand All @@ -27,6 +27,8 @@ import (
)

var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
require := require.New(ginkgo.GinkgoT())

ginkgo.It("subnets operations",
// use this for filtering tests by labels
// ref. https://onsi.github.io/ginkgo/#spec-labels
Expand All @@ -49,8 +51,7 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
validatorIDs, err := pChainClient.SampleValidators(ctx, constants.PrimaryNetworkID, 1)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(validatorIDs).Should(gomega.HaveLen(1))
require.NoError(err)
validatorID = validatorIDs[0]
})

Expand All @@ -71,7 +72,8 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
cancel()

subnetID = subnetTx.ID()
gomega.Expect(subnetID, err).Should(gomega.Not(gomega.Equal(constants.PrimaryNetworkID)))
require.NoError(err)
require.NotEqual(subnetID, constants.PrimaryNetworkID)
})

var subnetAssetID ids.ID
Expand All @@ -92,7 +94,7 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
subnetAssetID = subnetAssetTx.ID()
})

Expand All @@ -114,7 +116,7 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
})

ginkgo.By(fmt.Sprintf("Import the 100 MegaAvax of asset %s from the X-chain into the P-chain", subnetAssetID), func() {
Expand All @@ -125,7 +127,7 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
})

ginkgo.By("make subnet permissionless", func() {
Expand All @@ -148,7 +150,7 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
})

validatorStartTime := time.Now().Add(time.Minute)
Expand All @@ -172,7 +174,7 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
})

delegatorStartTime := validatorStartTime
Expand All @@ -193,7 +195,7 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
})
})
})
42 changes: 22 additions & 20 deletions tests/e2e/p/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ package p

import (
"context"
"errors"
"time"

ginkgo "github.com/onsi/ginkgo/v2"

"github.com/onsi/gomega"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/ids"
Expand All @@ -33,6 +32,8 @@ import (
// - Checks the expected value of the funding address

var _ = e2e.DescribePChain("[Workflow]", func() {
require := require.New(ginkgo.GinkgoT())

ginkgo.It("P-chain main operations",
// use this for filtering tests by labels
// ref. https://onsi.github.io/ginkgo/#spec-labels
Expand All @@ -55,7 +56,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultWalletCreationTimeout)
minValStake, minDelStake, err := pChainClient.GetMinStake(ctx, constants.PlatformChainID)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
tests.Outf("{{green}} minimal validator stake: %d {{/}}\n", minValStake)
tests.Outf("{{green}} minimal delegator stake: %d {{/}}\n", minDelStake)

Expand All @@ -64,7 +65,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
ctx, cancel = context.WithTimeout(context.Background(), e2e.DefaultWalletCreationTimeout)
fees, err := infoClient.GetTxFee(ctx)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
txFees := uint64(fees.TxFee)
tests.Outf("{{green}} txFee: %d {{/}}\n", txFees)

Expand All @@ -77,7 +78,8 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
pBalances, err := pWallet.Builder().GetBalance()
pBalance := pBalances[avaxAssetID]
minBalance := minValStake + txFees + minDelStake + txFees + toTransfer + txFees
gomega.Expect(pBalance, err).To(gomega.BeNumerically(">=", minBalance))
require.NoError(err)
require.GreaterOrEqual(pBalance, minBalance)
})
// create validator data
validatorStartTimeDiff := 30 * time.Second
Expand All @@ -86,7 +88,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
// Use a random node ID to ensure that repeated test runs
// will succeed against a persistent network.
validatorID, err := ids.ToNodeID(utils.RandomBytes(ids.NodeIDLen))
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

vdr := &txs.Validator{
NodeID: validatorID,
Expand All @@ -109,7 +111,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
})

ginkgo.By("issue add delegator tx", func() {
Expand All @@ -120,17 +122,17 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
})

// retrieve initial balances
pBalances, err := pWallet.Builder().GetBalance()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
pStartBalance := pBalances[avaxAssetID]
tests.Outf("{{blue}} P-chain balance before P->X export: %d {{/}}\n", pStartBalance)

xBalances, err := xWallet.Builder().GetFTBalance()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
xStartBalance := xBalances[avaxAssetID]
tests.Outf("{{blue}} X-chain balance before P->X export: %d {{/}}\n", xStartBalance)

Expand Down Expand Up @@ -160,22 +162,22 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
})

// check balances post export
pBalances, err = pWallet.Builder().GetBalance()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
pPreImportBalance := pBalances[avaxAssetID]
tests.Outf("{{blue}} P-chain balance after P->X export: %d {{/}}\n", pPreImportBalance)

xBalances, err = xWallet.Builder().GetFTBalance()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
xPreImportBalance := xBalances[avaxAssetID]
tests.Outf("{{blue}} X-chain balance after P->X export: %d {{/}}\n", xPreImportBalance)

gomega.Expect(xPreImportBalance).To(gomega.Equal(xStartBalance)) // import not performed yet
gomega.Expect(pPreImportBalance).To(gomega.Equal(pStartBalance - toTransfer - txFees))
require.Equal(xPreImportBalance, xStartBalance) // import not performed yet
require.Equal(pPreImportBalance, pStartBalance-toTransfer-txFees)

ginkgo.By("import avax from P into X chain", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
Expand All @@ -185,21 +187,21 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil(), "is context.DeadlineExceeded: %v", errors.Is(err, context.DeadlineExceeded))
require.NoError(err)
})

// check balances post import
pBalances, err = pWallet.Builder().GetBalance()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
pFinalBalance := pBalances[avaxAssetID]
tests.Outf("{{blue}} P-chain balance after P->X import: %d {{/}}\n", pFinalBalance)

xBalances, err = xWallet.Builder().GetFTBalance()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
xFinalBalance := xBalances[avaxAssetID]
tests.Outf("{{blue}} X-chain balance after P->X import: %d {{/}}\n", xFinalBalance)

gomega.Expect(xFinalBalance).To(gomega.Equal(xPreImportBalance + toTransfer - txFees)) // import not performed yet
gomega.Expect(pFinalBalance).To(gomega.Equal(pPreImportBalance))
require.Equal(xFinalBalance, xPreImportBalance+toTransfer-txFees) // import not performed yet
require.Equal(pFinalBalance, pPreImportBalance)
})
})
Loading

0 comments on commit 47997cf

Please sign in to comment.