diff --git a/.golangci.yaml b/.golangci.yaml index 735cd7d..ba0e7d4 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -109,6 +109,9 @@ issues: - path: tests/.*/*\.go linters: - paralleltest + - path: util/machine_nft_test\.go + linters: + - paralleltest - path: testutil/network/network.go linters: - gocognit diff --git a/lib/tests/e2e/cli_test.go b/lib/tests/e2e/cli_test.go index 130ce81..45ee65e 100644 --- a/lib/tests/e2e/cli_test.go +++ b/lib/tests/e2e/cli_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/suite" ) -func TestE2ETestSuite(t *testing.T) { +func TestE2ELibTestSuite(t *testing.T) { t.Parallel() cfg := network.DefaultConfig() cfg.NumValidators = 1 diff --git a/lib/tests/e2e/suite.go b/lib/tests/e2e/suite.go index 8a9a443..baf2c88 100644 --- a/lib/tests/e2e/suite.go +++ b/lib/tests/e2e/suite.go @@ -29,14 +29,14 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite { // SetupSuite initializes machine E2ETestSuite func (s *E2ETestSuite) SetupSuite() { - s.T().Log("setting up e2e test suite") + s.T().Log("setting up e2e lib test suite") s.network = network.New(s.T()) } // TearDownSuite clean up after testing func (s *E2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suite") + s.T().Log("tearing down e2e lib test suite") } func (s *E2ETestSuite) TestBankSendBroadcastTxWithFileLock() { diff --git a/lib/tx.go b/lib/tx.go index 7b734ac..6c8e486 100644 --- a/lib/tx.go +++ b/lib/tx.go @@ -7,6 +7,7 @@ import ( "io" "os" "strconv" + "sync" "syscall" comethttp "github.com/cometbft/cometbft/rpc/client/http" @@ -17,7 +18,10 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) -var ErrTypeAssertionFailed = errors.New("type assertion failed") +var ( + ErrTypeAssertionFailed = errors.New("type assertion failed") + LibSyncAccess sync.Mutex +) func init() { GetConfig() @@ -172,6 +176,8 @@ func broadcastTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (out // BroadcastTxWithFileLock broadcasts a transaction via gRPC and synchronises requests via a file lock. func BroadcastTxWithFileLock(fromAddress sdk.AccAddress, msgs ...sdk.Msg) (out *bytes.Buffer, err error) { + LibSyncAccess.Lock() + defer LibSyncAccess.Unlock() // open and lock file, if it exists file, err := openSequenceFile(fromAddress) if err != nil { diff --git a/tests/e2e/asset/cli_test.go b/tests/e2e/asset/cli_test.go index 13c295a..ba92ab3 100644 --- a/tests/e2e/asset/cli_test.go +++ b/tests/e2e/asset/cli_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/suite" ) -func TestE2ETestSuite(t *testing.T) { +func TestE2EAssetTestSuite(t *testing.T) { t.Parallel() cfg := network.LoaderDefaultConfig() cfg.NumValidators = 3 diff --git a/tests/e2e/asset/suite.go b/tests/e2e/asset/suite.go index 7688cad..90f2117 100644 --- a/tests/e2e/asset/suite.go +++ b/tests/e2e/asset/suite.go @@ -4,6 +4,7 @@ import ( "github.com/planetmint/planetmint-go/lib" "github.com/planetmint/planetmint-go/testutil/network" "github.com/planetmint/planetmint-go/testutil/sample" + "github.com/planetmint/planetmint-go/util" clitestutil "github.com/planetmint/planetmint-go/testutil/cli" e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e" @@ -29,7 +30,7 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite { // SetupSuite initializes asset E2ETestSuite func (s *E2ETestSuite) SetupSuite() { - s.T().Log("setting up e2e test suite") + s.T().Log("setting up e2e asset test suite") s.network = network.Load(s.T(), s.cfg) err := e2etestutil.AttestMachine(s.network, sample.Name, sample.Mnemonic, 0, sample.FeeDenom) @@ -38,7 +39,8 @@ func (s *E2ETestSuite) SetupSuite() { // TearDownSuite clean up after testing func (s *E2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suite") + util.TerminationWaitGroup.Wait() + s.T().Log("tearing down e2e asset test suite") } // TestNotarizeAsset notarizes asset over cli diff --git a/tests/e2e/dao/asset_distribution_suite.go b/tests/e2e/dao/asset_distribution_suite.go index 2c3d204..f342ec0 100644 --- a/tests/e2e/dao/asset_distribution_suite.go +++ b/tests/e2e/dao/asset_distribution_suite.go @@ -6,6 +6,7 @@ import ( clitestutil "github.com/planetmint/planetmint-go/testutil/cli" "github.com/planetmint/planetmint-go/testutil/network" + "github.com/planetmint/planetmint-go/util" daocli "github.com/planetmint/planetmint-go/x/dao/client/cli" daotypes "github.com/planetmint/planetmint-go/x/dao/types" "github.com/stretchr/testify/suite" @@ -25,7 +26,7 @@ func NewAssetDistributionE2ETestSuite(cfg network.Config) *AssetDistributionE2ET } func (s *AssetDistributionE2ETestSuite) SetupSuite() { - s.T().Log("setting up e2e test suite") + s.T().Log("setting up e2e dao distribution test suite") // set epochs: make sure to start after initial height of 7 s.distributionOffset = 5 @@ -41,7 +42,8 @@ func (s *AssetDistributionE2ETestSuite) SetupSuite() { } func (s *AssetDistributionE2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suites") + util.TerminationWaitGroup.Wait() + s.T().Log("tearing down e2e dao distribution test suites") } func (s *AssetDistributionE2ETestSuite) TestAssetDistribution() { diff --git a/tests/e2e/dao/cli_test.go b/tests/e2e/dao/cli_test.go index 6c33dd1..5550b08 100644 --- a/tests/e2e/dao/cli_test.go +++ b/tests/e2e/dao/cli_test.go @@ -8,31 +8,31 @@ import ( "github.com/stretchr/testify/suite" ) -func TestE2ETestSuite(t *testing.T) { +func TestE2EDaoTestSuite(t *testing.T) { cfg := network.LoaderDefaultConfig() cfg.NumValidators = 3 suite.Run(t, NewE2ETestSuite(cfg)) } -func TestPopE2ETestSuite(t *testing.T) { +func TestPopE2EDaoTestSuite(t *testing.T) { cfg := network.LoaderDefaultConfig() cfg.NumValidators = 3 suite.Run(t, NewPopSelectionE2ETestSuite(cfg)) } -func TestGasConsumptionE2ETestSuite(t *testing.T) { +func TestGasConsumptionE2EDaoTestSuite(t *testing.T) { cfg := network.LoaderDefaultConfig() cfg.NumValidators = 3 suite.Run(t, NewGasConsumptionE2ETestSuite(cfg)) } -func TestRestrictedMsgsE2ETestSuite(t *testing.T) { +func TestRestrictedMsgsE2EDaoTestSuite(t *testing.T) { cfg := network.LoaderDefaultConfig() cfg.NumValidators = 3 suite.Run(t, NewRestrictedMsgsE2ESuite(cfg)) } -func TestAssetDistributionE2ETestSuite(t *testing.T) { +func TestAssetDistributionE2EDaoTestSuite(t *testing.T) { cfg := network.LoaderDefaultConfig() cfg.NumValidators = 3 suite.Run(t, NewAssetDistributionE2ETestSuite(cfg)) diff --git a/tests/e2e/dao/gas_consumption_suite.go b/tests/e2e/dao/gas_consumption_suite.go index 7a2a3cf..a1bf47a 100644 --- a/tests/e2e/dao/gas_consumption_suite.go +++ b/tests/e2e/dao/gas_consumption_suite.go @@ -15,6 +15,7 @@ import ( "github.com/planetmint/planetmint-go/testutil/moduleobject" "github.com/planetmint/planetmint-go/testutil/network" "github.com/planetmint/planetmint-go/testutil/sample" + "github.com/planetmint/planetmint-go/util" daotypes "github.com/planetmint/planetmint-go/x/dao/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" @@ -63,7 +64,7 @@ func (s *GasConsumptionE2ETestSuite) createValAccount(cfg network.Config) (addre } func (s *GasConsumptionE2ETestSuite) SetupSuite() { - s.T().Log("setting up e2e test suite") + s.T().Log("setting up e2e dao gas consumption test suite") s.feeDenom = sample.FeeDenom s.cfg.Mnemonics = []string{sample.Mnemonic} @@ -93,7 +94,8 @@ func (s *GasConsumptionE2ETestSuite) SetupSuite() { } func (s *GasConsumptionE2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suites") + util.TerminationWaitGroup.Wait() + s.T().Log("tearing down e2e dao gas consumption test suites") } func (s *GasConsumptionE2ETestSuite) TestValidatorConsumption() { @@ -136,7 +138,7 @@ func (s *GasConsumptionE2ETestSuite) TestNonValidatorConsumptionOverflow() { _, err = clitestutil.GetRawLogFromTxOut(val, out) s.Require().Error(err) - assert.Equal(s.T(), "out of gas in location: ReadFlat; gasWanted: 200000, gasUsed: 200316: out of gas", err.Error()) + assert.Contains(s.T(), err.Error(), "out of gas") } func (s *GasConsumptionE2ETestSuite) createMsgs(from sdk.AccAddress, to sdk.AccAddress, n int) (msgs []sdk.Msg) { diff --git a/tests/e2e/dao/pop_participant_selection_suite.go b/tests/e2e/dao/pop_participant_selection_suite.go index 33a06fb..87fa425 100644 --- a/tests/e2e/dao/pop_participant_selection_suite.go +++ b/tests/e2e/dao/pop_participant_selection_suite.go @@ -17,6 +17,7 @@ import ( e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e" "github.com/planetmint/planetmint-go/testutil/network" "github.com/planetmint/planetmint-go/testutil/sample" + "github.com/planetmint/planetmint-go/util" daocli "github.com/planetmint/planetmint-go/x/dao/client/cli" daotypes "github.com/planetmint/planetmint-go/x/dao/types" "github.com/stretchr/testify/assert" @@ -61,7 +62,7 @@ func NewPopSelectionE2ETestSuite(cfg network.Config) *PopSelectionE2ETestSuite { } func (s *PopSelectionE2ETestSuite) SetupSuite() { - s.T().Log("setting up e2e test suite") + s.T().Log("setting up e2e dao pop selection test suite") s.popEpochs = 10 s.reissuanceEpochs = 60 @@ -86,7 +87,8 @@ func (s *PopSelectionE2ETestSuite) SetupSuite() { // TearDownSuite clean up after testing func (s *PopSelectionE2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suite") + util.TerminationWaitGroup.Wait() + s.T().Log("tearing down e2e dao pop selection test suite") } func (s *PopSelectionE2ETestSuite) perpareLocalTest() testutil.BufferWriter { @@ -244,6 +246,8 @@ func (s *PopSelectionE2ETestSuite) TestTokenDistribution1() { s.Require().NoError(s.network.WaitForNextBlock()) s.Require().NoError(s.network.WaitForNextBlock()) s.Require().NoError(s.network.WaitForNextBlock()) + s.Require().NoError(s.network.WaitForNextBlock()) + s.Require().NoError(s.network.WaitForNextBlock()) s.VerifyTokens(daoGenState.Params.ClaimDenom) } diff --git a/tests/e2e/dao/restricted_msgs_suite.go b/tests/e2e/dao/restricted_msgs_suite.go index e4cf52d..35749b5 100644 --- a/tests/e2e/dao/restricted_msgs_suite.go +++ b/tests/e2e/dao/restricted_msgs_suite.go @@ -6,6 +6,7 @@ import ( e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e" "github.com/planetmint/planetmint-go/testutil/network" "github.com/planetmint/planetmint-go/testutil/sample" + "github.com/planetmint/planetmint-go/util" daotypes "github.com/planetmint/planetmint-go/x/dao/types" machinetypes "github.com/planetmint/planetmint-go/x/machine/types" "github.com/stretchr/testify/suite" @@ -34,7 +35,7 @@ func NewRestrictedMsgsE2ESuite(cfg network.Config) *RestrictedMsgsE2ESuite { } func (s *RestrictedMsgsE2ESuite) SetupSuite() { - s.T().Log("setting up e2e test suite") + s.T().Log("setting up e2e dao restricted msg test suite") s.network = network.Load(s.T(), s.cfg) account, err := e2etestutil.CreateAccount(s.network, sample.Name, sample.Mnemonic) @@ -44,7 +45,8 @@ func (s *RestrictedMsgsE2ESuite) SetupSuite() { } func (s *RestrictedMsgsE2ESuite) TearDownSuite() { - s.T().Log("tearing down e2e test suite") + util.TerminationWaitGroup.Wait() + s.T().Log("tearing down e2e dao restricted msg test suite") } func (s *RestrictedMsgsE2ESuite) TestRestrictedMsgsValidator() { diff --git a/tests/e2e/dao/suite.go b/tests/e2e/dao/suite.go index 1ec8e81..b141f82 100644 --- a/tests/e2e/dao/suite.go +++ b/tests/e2e/dao/suite.go @@ -14,6 +14,7 @@ import ( e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e" "github.com/planetmint/planetmint-go/testutil/network" "github.com/planetmint/planetmint-go/testutil/sample" + "github.com/planetmint/planetmint-go/util" daocli "github.com/planetmint/planetmint-go/x/dao/client/cli" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" @@ -48,7 +49,7 @@ func (s *E2ETestSuite) SetupSuite() { s.reissuanceEpochs = 25 s.distributionOffset = 5 - s.T().Log("setting up e2e test suite") + s.T().Log("setting up e2e dao test suite") // Setup MintAddress parameter in genesis state // use sample.Mnemonic to make mint address deterministic for test @@ -109,7 +110,8 @@ func (s *E2ETestSuite) SetupSuite() { // TearDownSuite clean up after testing func (s *E2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suite") + util.TerminationWaitGroup.Wait() + s.T().Log("tearing down e2e dao test suite") } func (s *E2ETestSuite) TestMintToken() { diff --git a/tests/e2e/machine/cli_test.go b/tests/e2e/machine/cli_test.go index 1d55557..312820d 100644 --- a/tests/e2e/machine/cli_test.go +++ b/tests/e2e/machine/cli_test.go @@ -8,8 +8,7 @@ import ( "github.com/stretchr/testify/suite" ) -func TestE2ETestSuite(t *testing.T) { - t.Parallel() +func TestE2EMachineTestSuite(t *testing.T) { cfg := network.LoaderDefaultConfig() cfg.NumValidators = 3 suite.Run(t, NewE2ETestSuite(cfg)) diff --git a/tests/e2e/machine/suite.go b/tests/e2e/machine/suite.go index 8b267bd..cf81d44 100644 --- a/tests/e2e/machine/suite.go +++ b/tests/e2e/machine/suite.go @@ -5,6 +5,7 @@ import ( clitestutil "github.com/planetmint/planetmint-go/testutil/cli" "github.com/planetmint/planetmint-go/testutil/network" "github.com/planetmint/planetmint-go/testutil/sample" + "github.com/planetmint/planetmint-go/util" machinecli "github.com/planetmint/planetmint-go/x/machine/client/cli" machinetypes "github.com/planetmint/planetmint-go/x/machine/types" @@ -35,7 +36,7 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite { // SetupSuite initializes machine E2ETestSuite func (s *E2ETestSuite) SetupSuite() { - s.T().Log("setting up e2e test suite") + s.T().Log("setting up e2e machine test suite") s.feeDenom = sample.FeeDenom s.network = network.Load(s.T(), s.cfg) @@ -49,7 +50,8 @@ func (s *E2ETestSuite) SetupSuite() { // TearDownSuite clean up after testing func (s *E2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suite") + util.TerminationWaitGroup.Wait() + s.T().Log("tearing down e2e machine test suite") } // TestAttestMachine attests machine and query attested machine from chain diff --git a/util/issue_commands.go b/util/issue_commands.go index a8147b8..b46bcd4 100644 --- a/util/issue_commands.go +++ b/util/issue_commands.go @@ -14,7 +14,9 @@ import ( func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingValidatorAddress string, msg sdk.Msg) { ctx := sdk.UnwrapSDKContext(goCtx) GetAppLogger().Info(ctx, loggingContext+": "+msg.String()) + TerminationWaitGroup.Add(1) go func() { + defer TerminationWaitGroup.Done() ctx := sdk.UnwrapSDKContext(goCtx) addr := sdk.MustAccAddressFromBech32(sendingValidatorAddress) txJSON, err := lib.BuildUnsignedTx(addr, msg) diff --git a/util/machine_nft_test.go b/util/machine_nft_test.go index a87a5c8..717be66 100644 --- a/util/machine_nft_test.go +++ b/util/machine_nft_test.go @@ -16,7 +16,6 @@ import ( ) func TestRegisterNFT(t *testing.T) { - t.Parallel() url := "https://testnet-assets.rddl.io/register_asset" contract := `{"entity":{"domain":"testnet-assets.rddl.io"},"issuer_pubkey":"020000000000000000000000000000000000000000000000000000000000000000","machine_addr":"plmnt10mq5nj8jhh27z7ejnz2ql3nh0qhzjnfvy50877","name":"machine","precision":0,"version":0}` asset := "0000000000000000000000000000000000000000000000000000000000000000" @@ -28,8 +27,6 @@ func TestRegisterNFT(t *testing.T) { } func TestMachineNFTIssuance(t *testing.T) { - t.Parallel() - elements.Client = &elementsmocks.MockClient{} util.RegisterAssetServiceHTTPClient = &mocks.MockClient{} _, ctx := keeper.MachineKeeper(t) diff --git a/util/sync.go b/util/sync.go new file mode 100644 index 0000000..ccb3386 --- /dev/null +++ b/util/sync.go @@ -0,0 +1,5 @@ +package util + +import "sync" + +var TerminationWaitGroup sync.WaitGroup