From 8236eda53a4de23982a7baf7168f01ef9a889334 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 5 Jul 2024 12:25:18 +0200 Subject: [PATCH 01/11] test: expand apphash test with more state machine msgs --- app/consistent_apphash_test.go | 458 +++++++++++++++++++++++++++------ 1 file changed, 377 insertions(+), 81 deletions(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index 44c4272964..b7dca2420b 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -3,134 +3,300 @@ package app_test import ( "fmt" "testing" + "time" "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/user" testutil "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/blobfactory" + "github.com/celestiaorg/celestia-app/test/util/testfactory" + + appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + + blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" + "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + crisisTypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distribution "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/proto/tendermint/version" - coretypes "github.com/tendermint/tendermint/types" ) -type SdkTx struct { - sdkMsgs []sdk.Msg - txOptions []user.TxOption -} - type BlobTx struct { author string - blobs []*tmproto.Blob + blobs []*blob.Blob txOptions []user.TxOption } -// TestConsistentAppHash executes a set of txs, generates an app hash, +// TestConsistentAppHash executes all state machine messages, generates an app hash, // and compares it against a previously generated hash from the same set of transactions. // App hashes across different commits should be consistent. func TestConsistentAppHash(t *testing.T) { - // App hash produced from executing txs on this branch - expectedAppHash := []byte{9, 208, 117, 101, 108, 61, 146, 58, 26, 190, 199, 124, 76, 178, 84, 74, 54, 159, 76, 187, 2, 169, 128, 87, 70, 78, 8, 192, 28, 144, 116, 117} + // Expected app hash produced by v1.x - https://github.com/celestiaorg/celestia-app/blob/v1.x/app/consistent_apphash_test.go + // expectedAppHash := []byte{9, 208, 117, 101, 108, 61, 146, 58, 26, 190, 199, 124, 76, 178, 84, 74, 54, 159, 76, 187, 2, 169, 128, 87, 70, 78, 8, 192, 28, 144, 116, 117} // Initialize testApp testApp := testutil.NewTestApp() - enc := encoding.MakeConfig(app.ModuleEncodingRegisters...) + // Create deterministic keys kr, pubKeys := deterministicKeyRing(enc.Codec) - recs, err := kr.List() + // Apply genesis state to the app. + valKeyRing, _, err := testutil.SetupDeterministicGenesisState(testApp, pubKeys, 20_000_000_000, app.DefaultInitialConsensusParams()) require.NoError(t, err) - accountNames := make([]string, 0, len(recs)) - // Get the name of the records - for _, rec := range recs { - accountNames = append(accountNames, rec.Name) - } + // ------------ Genesis User Accounts ------------ - // Apply genesis state to the app. - _, _, err = testutil.SetupDeterministicGenesisState(testApp, pubKeys, 1_000_000_000, app.DefaultInitialConsensusParams()) - require.NoError(t, err) + // Get account names and addresses from the keyring + accountNames := testfactory.GetAccountNames(kr) + accountAddresses := testfactory.GetAddresses(kr) // Query keyring account infos accountInfos := queryAccountInfo(testApp, accountNames, kr) // Create accounts for the signer - accounts := make([]*user.Account, 0, len(accountInfos)) - for i, accountInfo := range accountInfos { - account := user.NewAccount(accountNames[i], accountInfo.AccountNum, accountInfo.Sequence) - accounts = append(accounts, account) - } + accounts := createAccounts(accountInfos, accountNames) - // Create a signer with keyring accounts - signer, err := user.NewTxSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, accounts...) + // Create a signer with accounts + signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, app.DefaultInitialVersion, accounts...) require.NoError(t, err) - amount := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(1000))) + // ------------ Genesis Validator Accounts ------------ - // Create an SDK Tx - sdkTx := SdkTx{ - sdkMsgs: []sdk.Msg{ - banktypes.NewMsgSend(signer.Account(accountNames[0]).Address(), - signer.Account(accountNames[1]).Address(), - amount), - }, - txOptions: blobfactory.DefaultTxOpts(), + // Validators from genesis state + genValidators := testApp.StakingKeeper.GetAllValidators(testApp.NewContext(false, tmproto.Header{})) + + // Get validator account names from the validator keyring + valAccountNames := testfactory.GetAccountNames(valKeyRing) + + // Query validator account infos + valAccountInfos := queryAccountInfo(testApp, valAccountNames, valKeyRing) + + // Create accounts for the validators' signer + valAccounts := createAccounts(valAccountInfos, valAccountNames) + + // Create a signer with validator accounts + valSigner, err := user.NewSigner(valKeyRing, enc.TxConfig, testutil.ChainID, app.DefaultInitialVersion, valAccounts...) + require.NoError(t, err) + + // ----------- Create SDK Messages ------------ + + amount := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(1_000))) + depositAmount := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(10000000000))) + twoInt := sdk.NewInt(2) + + // ---------------- First Block ------------ + var firstBlockSdkMsgs []sdk.Msg + + // NewMsgSend - sends funds from account-0 to account-1 + sendFundsMsg := banktypes.NewMsgSend(accountAddresses[0], accountAddresses[1], amount) + firstBlockSdkMsgs = append(firstBlockSdkMsgs, sendFundsMsg) + + // MultiSend - creates a multi-send transaction from account-0 to account-1 + multiSendFundsMsg := banktypes.NewMsgMultiSend([]banktypes.Input{ + banktypes.NewInput( + accountAddresses[0], + amount, + ), + }, + []banktypes.Output{ + banktypes.NewOutput( + accountAddresses[1], + amount, + ), + }) + firstBlockSdkMsgs = append(firstBlockSdkMsgs, multiSendFundsMsg) + + // NewMsgGrant - grants authorization to account-1 + grantExpiration := time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC) + authorization := authz.NewGenericAuthorization(blobtypes.URLMsgPayForBlobs) + msgGrant, err := authz.NewMsgGrant( + accountAddresses[0], + accountAddresses[1], + authorization, + &grantExpiration, + ) + require.NoError(t, err) + firstBlockSdkMsgs = append(firstBlockSdkMsgs, msgGrant) + + // MsgVerifyInvariant - verifies the nonnegative-outstanding invariant within the bank module for the account-0 + msgVerifyInvariant := crisisTypes.NewMsgVerifyInvariant(accountAddresses[0], banktypes.ModuleName, "nonnegative-outstanding") + firstBlockSdkMsgs = append(firstBlockSdkMsgs, msgVerifyInvariant) + + // MsgGrantAllowance - creates a grant allowance for account-1 + basicAllowance := feegrant.BasicAllowance{ + SpendLimit: sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(1000))), } + feegrantMsg, err := feegrant.NewMsgGrantAllowance(&basicAllowance, accountAddresses[0], accountAddresses[1]) + require.NoError(t, err) + firstBlockSdkMsgs = append(firstBlockSdkMsgs, feegrantMsg) - // Create a Blob Tx - blobTx := BlobTx{ - author: accountNames[2], - blobs: []*tmproto.Blob{New(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion)}, - txOptions: blobfactory.DefaultTxOpts(), + // NewMsgSubmitProposal - submits a proposal to send funds from the governance account to account-1 + govAccount := testApp.GovKeeper.GetGovernanceAccount(testApp.NewContext(false, tmproto.Header{})).GetAddress() + msgSend := banktypes.MsgSend{ + FromAddress: govAccount.String(), + ToAddress: accountAddresses[1].String(), + Amount: amount, } + proposal, err := govtypes.NewMsgSubmitProposal([]sdk.Msg{&msgSend}, amount, accountAddresses[0].String(), "") + require.NoError(t, err) + firstBlockSdkMsgs = append(firstBlockSdkMsgs, proposal) - // Create SDK Tx - rawSdkTx, err := signer.CreateTx(sdkTx.sdkMsgs, sdkTx.txOptions...) + // NewMsgDeposit - deposits funds to a governance proposal + msgDeposit := govtypes.NewMsgDeposit(accountAddresses[0], 1, depositAmount) + firstBlockSdkMsgs = append(firstBlockSdkMsgs, msgDeposit) + + // NewMsgCreateValidator - creates a new validator + msgCreateValidator, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(accountAddresses[6]), + ed25519.GenPrivKeyFromSecret([]byte("validator")).PubKey(), + amount[0], + stakingtypes.NewDescription("taco tuesday", "my keybase", "www.celestia.org", "ping @celestiaorg on twitter", "fake validator"), + stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(6, 0o2), sdk.NewDecWithPrec(12, 0o2), sdk.NewDecWithPrec(1, 0o2)), + sdk.OneInt()) require.NoError(t, err) + firstBlockSdkMsgs = append(firstBlockSdkMsgs, msgCreateValidator) - // Create Blob Tx - rawBlobTx, _, err := signer.CreatePayForBlobs(blobTx.author, blobTx.blobs, blobTx.txOptions...) + // NewMsgDelegate - delegates funds to validator-0 + msgDelegate := stakingtypes.NewMsgDelegate(accountAddresses[0], genValidators[0].GetOperator(), amount[0]) + firstBlockSdkMsgs = append(firstBlockSdkMsgs, msgDelegate) + + // NewMsgBeginRedelegate - re-delegates funds from validator-0 to validator-1 + msgBeginRedelegate := stakingtypes.NewMsgBeginRedelegate(accountAddresses[0], genValidators[0].GetOperator(), genValidators[1].GetOperator(), amount[0]) + firstBlockSdkMsgs = append(firstBlockSdkMsgs, msgBeginRedelegate) + + // ------------ Second Block ------------ + + var secondBlockSdkMsgs []sdk.Msg + + // NewMsgVote - votes yes on a governance proposal + msgVote := govtypes.NewMsgVote(accountAddresses[0], 1, govtypes.VoteOption_VOTE_OPTION_YES, "") + secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgVote) + + // NewMsgRevoke - revokes authorization from account-1 + msgRevoke := authz.NewMsgRevoke( + accountAddresses[0], + accountAddresses[1], + blobtypes.URLMsgPayForBlobs, + ) + + // NewMsgExec - executes the revoke authorization message + msgExec := authz.NewMsgExec(accountAddresses[0], []sdk.Msg{&msgRevoke}) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, &msgExec) + + // NewMsgVoteWeighted - votes with a weighted vote + msgVoteWeighted := govtypes.NewMsgVoteWeighted( + accountAddresses[0], + 1, + govtypes.WeightedVoteOptions([]*govtypes.WeightedVoteOption{{Option: govtypes.OptionYes, Weight: "1.0"}}), // Cast the slice to the expected type + "", + ) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgVoteWeighted) + + // NewMsgEditValidator - edits the newly created validator's description + msgEditValidator := stakingtypes.NewMsgEditValidator(sdk.ValAddress(accountAddresses[6]), stakingtypes.NewDescription("add", "new", "val", "desc", "."), nil, &twoInt) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgEditValidator) + + // NewMsgUndelegate - undelegates funds from validator-1 + msgUndelegate := stakingtypes.NewMsgUndelegate(accountAddresses[0], genValidators[1].GetOperator(), amount[0]) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgUndelegate) + + // NewMsgDelegate - delegates funds to validator-0 + msgDelegate = stakingtypes.NewMsgDelegate(accountAddresses[0], genValidators[0].GetOperator(), amount[0]) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgDelegate) + + // Messages are split in two blocks, this tx is part of the second block therefore the block height is incremented by 2 + blockHeight := testApp.LastBlockHeight() + 2 + // NewMsgCancelUnbondingDelegation - cancels unbonding delegation from validator-1 + msgCancelUnbondingDelegation := stakingtypes.NewMsgCancelUnbondingDelegation(accountAddresses[0], genValidators[1].GetOperator(), blockHeight, amount[0]) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgCancelUnbondingDelegation) + + // NewMsgSetWithdrawAddress - sets the withdraw address for account-0 + msgSetWithdrawAddress := distribution.NewMsgSetWithdrawAddress(accountAddresses[0], accountAddresses[1]) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgSetWithdrawAddress) + + // NewMsgRevokeAllowance - revokes the allowance granted to account-1 + msgRevokeAllowance := feegrant.NewMsgRevokeAllowance(accountAddresses[0], accountAddresses[1]) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, &msgRevokeAllowance) + + // NewMsgFundCommunityPool - funds the community pool + msgFundCommunityPool := distribution.NewMsgFundCommunityPool(amount, accountAddresses[0]) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgFundCommunityPool) + + // NewMsgWithdrawDelegatorReward - withdraws delegator rewards + msgWithdrawDelegatorReward := distribution.NewMsgWithdrawDelegatorReward(accountAddresses[0], genValidators[0].GetOperator()) + secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgWithdrawDelegatorReward) + + // ------------ Third Block ------------ + + // The transactions within the third block are signed by the validator's signer + var thirdBlockSdkMsgs []sdk.Msg + + // NewMsgWithdrawValidatorCommission - withdraws validator-0's commission + msgWithdrawValidatorCommission := distribution.NewMsgWithdrawValidatorCommission(genValidators[0].GetOperator()) + thirdBlockSdkMsgs = append(thirdBlockSdkMsgs, msgWithdrawValidatorCommission) + + // NewMsgUnjail - unjails validator-3 + msgUnjail := slashingtypes.NewMsgUnjail(genValidators[3].GetOperator()) + thirdBlockSdkMsgs = append(thirdBlockSdkMsgs, msgUnjail) + + // ------------ Construct Txs ------------ + + // Create SDK transactions from the list of messages + // and separate them into 3 different blocks + firstBlockRawTxs, err := processSdkMessages(signer, firstBlockSdkMsgs) require.NoError(t, err) - // BeginBlock - header := tmproto.Header{ - Version: version.Consensus{App: 1}, - Height: testApp.LastBlockHeight() + 1, + secondBlockRawTxs, err := processSdkMessages(signer, secondBlockSdkMsgs) + require.NoError(t, err) + + validatorRawTxs, err := processSdkMessages(valSigner, thirdBlockSdkMsgs) + require.NoError(t, err) + + // Create a Blob Tx + blobTx := BlobTx{ + author: accountNames[1], + blobs: []*blob.Blob{blob.New(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion)}, + txOptions: blobfactory.DefaultTxOpts(), } - testApp.BeginBlock(abci.RequestBeginBlock{Header: header}) + rawBlobTx, _, err := signer.CreatePayForBlobs(blobTx.author, blobTx.blobs, blobTx.txOptions...) + require.NoError(t, err) - // Deliver SDK Tx - resp := testApp.DeliverTx(abci.RequestDeliverTx{Tx: rawSdkTx}) - require.EqualValues(t, 0, resp.Code, resp.Log) + // Convert validators to abci validators + abciValidators, err := convertToABCIValidators(genValidators) + require.NoError(t, err) - // Deliver Blob Tx - blob, isBlobTx := coretypes.UnmarshalBlobTx(rawBlobTx) - require.True(t, isBlobTx) - resp = testApp.DeliverTx(abci.RequestDeliverTx{Tx: blob.Tx}) - require.EqualValues(t, 0, resp.Code, resp.Log) + // Execute the first block + _, firstBlockCommitHash, err := executeTxs(testApp, []byte{}, firstBlockRawTxs, abciValidators, testApp.LastCommitID().Hash) + require.NoError(t, err) - // EndBlock - testApp.EndBlock(abci.RequestEndBlock{Height: header.Height}) + // Execute the second block + _, secondAppHash, err := executeTxs(testApp, rawBlobTx, secondBlockRawTxs, abciValidators, firstBlockCommitHash) + require.NoError(t, err) - // Commit the state - testApp.Commit() + // Execute the final block and get the data hash alongside the final app hash + _, finalAppHash, err := executeTxs(testApp, []byte{}, validatorRawTxs, abciValidators, secondAppHash) + require.NoError(t, err) - // Get the app hash - appHash := testApp.LastCommitID().Hash + fmt.Println(finalAppHash, "APP HASH") // Require that the app hash is equal to the app hash produced on a different commit - require.Equal(t, expectedAppHash, appHash) + // require.Equal(t, expectedAppHash, appHash) } // fixedNamespace returns a hardcoded namespace @@ -172,16 +338,118 @@ func deterministicKeyRing(cdc codec.Codec) (keyring.Keyring, []types.PubKey) { return kb, pubKeys } -func getAddress(account string, kr keyring.Keyring) sdk.AccAddress { - rec, err := kr.Key(account) - if err != nil { - panic(err) +// processSdkMessages takes a list of sdk messages, forms transactions, signs them +// and returns a list of raw transactions +func processSdkMessages(signer *user.Signer, sdkMessages []sdk.Msg) ([][]byte, error) { + rawSdkTxs := make([][]byte, 0, len(sdkMessages)) + for _, msg := range sdkMessages { + rawSdkTx, err := signer.CreateTx([]sdk.Msg{msg}, blobfactory.DefaultTxOpts()...) + if err != nil { + return nil, err + } + + signerAddress := msg.GetSigners()[0] + signerAccount := signer.AccountByAddress(signerAddress) + err = signer.SetSequence(signerAccount.Name(), signerAccount.Sequence()+1) + if err != nil { + return nil, err + } + + rawSdkTxs = append(rawSdkTxs, rawSdkTx) } - addr, err := rec.GetAddress() - if err != nil { - panic(err) + return rawSdkTxs, nil +} + +// executeTxs executes a set of transactions and returns the data hash and app hash +func executeTxs(testApp *app.App, rawBlobTx []byte, rawSdkTxs [][]byte, validators []abci.Validator, lastCommitHash []byte) ([]byte, []byte, error) { + height := testApp.LastBlockHeight() + 1 + chainID := testApp.GetChainID() + + genesisTime := testutil.GenesisTime + + // Prepare Proposal + resPrePareProposal := testApp.PrepareProposal(abci.RequestPrepareProposal{ + BlockData: &tmproto.Data{ + Txs: rawSdkTxs, + }, + ChainId: chainID, + Height: height, + Time: genesisTime.Add(time.Duration(height) * time.Minute), + }) + + dataHash := resPrePareProposal.BlockData.Hash + + header := tmproto.Header{ + Version: version.Consensus{App: 1}, + DataHash: resPrePareProposal.BlockData.Hash, + ChainID: chainID, + Time: genesisTime.Add(time.Duration(height) * time.Minute), + Height: height, + LastCommitHash: lastCommitHash, } - return addr + + // Process Proposal + resProcessProposal := testApp.ProcessProposal(abci.RequestProcessProposal{ + BlockData: resPrePareProposal.BlockData, + Header: header, + }, + ) + if abci.ResponseProcessProposal_ACCEPT != resProcessProposal.Result { + return nil, nil, fmt.Errorf("ProcessProposal failed: %v", resProcessProposal.Result) + } + + // Begin block + validator3Signed := height == 2 // Validator 3 signs only the first block + testApp.BeginBlock(abci.RequestBeginBlock{ + Header: header, + LastCommitInfo: abci.LastCommitInfo{ + Votes: []abci.VoteInfo{ + // In order to withdraw commission for this validator + { + Validator: validators[0], + SignedLastBlock: true, + }, + // In order to jail this validator + { + Validator: validators[3], + SignedLastBlock: validator3Signed, + }, + }, + }, + }) + + // Deliver SDK Txs + for i, rawSdkTx := range rawSdkTxs { + resp := testApp.DeliverTx(abci.RequestDeliverTx{Tx: rawSdkTx}) + if resp.Code != uint32(0) { + return nil, nil, fmt.Errorf("DeliverTx failed for the message at index %d: %s", i, resp.Log) + } + } + + // Deliver Blob Txs + if len(rawBlobTx) != 0 { + // Deliver Blob Tx + blob, isBlobTx := blob.UnmarshalBlobTx(rawBlobTx) + if !isBlobTx { + return nil, nil, fmt.Errorf("Not a valid BlobTx") + } + + respDeliverTx := testApp.DeliverTx(abci.RequestDeliverTx{Tx: blob.Tx}) + if respDeliverTx.Code != uint32(0) { + return nil, nil, fmt.Errorf("DeliverTx failed for the BlobTx: %s", respDeliverTx.Log) + } + } + + // EndBlock + testApp.EndBlock(abci.RequestEndBlock{Height: header.Height}) + + // Commit the state + testApp.Commit() + + // Get the app hash + appHash := testApp.LastCommitID().Hash + + return dataHash, appHash, nil } func queryAccountInfo(capp *app.App, accs []string, kr keyring.Keyring) []blobfactory.AccountInfo { @@ -197,12 +465,40 @@ func queryAccountInfo(capp *app.App, accs []string, kr keyring.Keyring) []blobfa return infos } -// New creates a new tmproto.Blob from the provided data -func New(ns appns.Namespace, blob []byte, shareVersion uint8) *tmproto.Blob { - return &tmproto.Blob{ - NamespaceId: ns.ID, - Data: blob, - ShareVersion: uint32(shareVersion), - NamespaceVersion: uint32(ns.Version), +func getAddress(account string, kr keyring.Keyring) sdk.AccAddress { + rec, err := kr.Key(account) + if err != nil { + panic(err) + } + addr, err := rec.GetAddress() + if err != nil { + panic(err) + } + return addr +} + +// createAccounts creates a list of user.Accounts from a list of accountInfos +func createAccounts(accountInfos []blobfactory.AccountInfo, accountNames []string) []*user.Account { + accounts := make([]*user.Account, 0, len(accountInfos)) + for i, accountInfo := range accountInfos { + account := user.NewAccount(accountNames[i], accountInfo.AccountNum, accountInfo.Sequence) + accounts = append(accounts, account) + } + return accounts +} + +// convertToABCIValidators converts a list of staking.Validator to a list of abci.Validator +func convertToABCIValidators(genValidators []stakingtypes.Validator) ([]abci.Validator, error) { + abciValidators := make([]abci.Validator, 0, len(genValidators)) + for _, val := range genValidators { + consAddr, err := val.GetConsAddr() + if err != nil { + return nil, err + } + abciValidators = append(abciValidators, abci.Validator{ + Address: consAddr, + Power: 100, + }) } + return abciValidators, nil } From 8f3e0b7f0b732bca62a5bbbbd3fcae0e2dd520e7 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 5 Jul 2024 13:06:13 +0200 Subject: [PATCH 02/11] test(v1.x): expand apphash test with all state machine msgs --- app/consistent_apphash_test.go | 26 ++++++++--- test/util/common.go | 28 ++++++++++++ test/util/genesis/modifier.go | 11 +++++ test/util/test_app.go | 79 +++++++++++++++++---------------- test/util/testfactory/common.go | 28 ++++++++++++ 5 files changed, 127 insertions(+), 45 deletions(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index b7dca2420b..754ce143fc 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -35,11 +35,12 @@ import ( abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/proto/tendermint/version" + coretypes "github.com/tendermint/tendermint/types" ) type BlobTx struct { author string - blobs []*blob.Blob + blobs []*tmproto.Blob txOptions []user.TxOption } @@ -74,7 +75,7 @@ func TestConsistentAppHash(t *testing.T) { accounts := createAccounts(accountInfos, accountNames) // Create a signer with accounts - signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, app.DefaultInitialVersion, accounts...) + signer, err := user.NewTxSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, accounts...) require.NoError(t, err) // ------------ Genesis Validator Accounts ------------ @@ -92,7 +93,7 @@ func TestConsistentAppHash(t *testing.T) { valAccounts := createAccounts(valAccountInfos, valAccountNames) // Create a signer with validator accounts - valSigner, err := user.NewSigner(valKeyRing, enc.TxConfig, testutil.ChainID, app.DefaultInitialVersion, valAccounts...) + valSigner, err := user.NewTxSigner(valKeyRing, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, valAccounts...) require.NoError(t, err) // ----------- Create SDK Messages ------------ @@ -271,7 +272,7 @@ func TestConsistentAppHash(t *testing.T) { // Create a Blob Tx blobTx := BlobTx{ author: accountNames[1], - blobs: []*blob.Blob{blob.New(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion)}, + blobs: []*tmproto.Blob{New(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion)}, txOptions: blobfactory.DefaultTxOpts(), } rawBlobTx, _, err := signer.CreatePayForBlobs(blobTx.author, blobTx.blobs, blobTx.txOptions...) @@ -290,10 +291,11 @@ func TestConsistentAppHash(t *testing.T) { require.NoError(t, err) // Execute the final block and get the data hash alongside the final app hash - _, finalAppHash, err := executeTxs(testApp, []byte{}, validatorRawTxs, abciValidators, secondAppHash) + dataHash, finalAppHash, err := executeTxs(testApp, []byte{}, validatorRawTxs, abciValidators, secondAppHash) require.NoError(t, err) fmt.Println(finalAppHash, "APP HASH") + fmt.Println(dataHash, "DATA HASH") // Require that the app hash is equal to the app hash produced on a different commit // require.Equal(t, expectedAppHash, appHash) @@ -340,7 +342,7 @@ func deterministicKeyRing(cdc codec.Codec) (keyring.Keyring, []types.PubKey) { // processSdkMessages takes a list of sdk messages, forms transactions, signs them // and returns a list of raw transactions -func processSdkMessages(signer *user.Signer, sdkMessages []sdk.Msg) ([][]byte, error) { +func processSdkMessages(signer *user.TxSigner, sdkMessages []sdk.Msg) ([][]byte, error) { rawSdkTxs := make([][]byte, 0, len(sdkMessages)) for _, msg := range sdkMessages { rawSdkTx, err := signer.CreateTx([]sdk.Msg{msg}, blobfactory.DefaultTxOpts()...) @@ -429,7 +431,7 @@ func executeTxs(testApp *app.App, rawBlobTx []byte, rawSdkTxs [][]byte, validato // Deliver Blob Txs if len(rawBlobTx) != 0 { // Deliver Blob Tx - blob, isBlobTx := blob.UnmarshalBlobTx(rawBlobTx) + blob, isBlobTx := coretypes.UnmarshalBlobTx(rawBlobTx) if !isBlobTx { return nil, nil, fmt.Errorf("Not a valid BlobTx") } @@ -502,3 +504,13 @@ func convertToABCIValidators(genValidators []stakingtypes.Validator) ([]abci.Val } return abciValidators, nil } + +// New creates a new tmproto.Blob from the provided data +func New(ns appns.Namespace, blob []byte, shareVersion uint8) *tmproto.Blob { + return &tmproto.Blob{ + NamespaceId: ns.ID, + Data: blob, + ShareVersion: uint32(shareVersion), + NamespaceVersion: uint32(ns.Version), + } +} diff --git a/test/util/common.go b/test/util/common.go index fcd657744d..cfd347f7fc 100644 --- a/test/util/common.go +++ b/test/util/common.go @@ -39,6 +39,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" gethcommon "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" + tmed "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmversion "github.com/tendermint/tendermint/proto/tendermint/version" @@ -58,6 +59,33 @@ var ( MinCommissionRate: sdk.NewDecWithPrec(0, 0), } + // HardcodedConsensusPrivKeys + FixedConsensusPrivKeys = []tmed.PrivKey{ + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456389012")), + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456389013")), + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456389014")), + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456389015")), + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456389016")), + } + + FixedNetWorkPrivKeys = []tmed.PrivKey{ + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456786012")), + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456786013")), + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456786014")), + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456786015")), + tmed.GenPrivKeyFromSecret([]byte("12345678901234567890123456786016")), + } + + // FixedMnemonics is a set of fixed mnemonics for testing. + // Account names are: validator1, validator2, validator3, validator4, validator5 + FixedMnemonics = []string{ + "body world north giggle crop reduce height copper damp next verify orphan lens loan adjust inform utility theory now ranch motion opinion crowd fun", + "body champion street fat bone above office guess waste vivid gift around approve elevator depth fiber alarm usual skirt like organ space antique silk", + "cheap alpha render punch clap prize duty drive steel situate person radar smooth elegant over chronic wait danger thumb soft letter spatial acquire rough", + "outdoor ramp suspect office disagree world attend vanish small wish capable fall wall soon damp session emotion chest toss viable meat host clerk truth", + "ability evidence casino cram weasel chest brush bridge sister blur onion found glad own mansion amateur expect force fun dragon famous alien appear open", + } + // ConsPrivKeys generate ed25519 ConsPrivKeys to be used for validator operator keys ConsPrivKeys = []ccrypto.PrivKey{ ed25519.GenPrivKey(), diff --git a/test/util/genesis/modifier.go b/test/util/genesis/modifier.go index 9ffe274d11..9effe2859a 100644 --- a/test/util/genesis/modifier.go +++ b/test/util/genesis/modifier.go @@ -13,6 +13,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Modifier allows for arbitrary changes to be made on the genesis state @@ -30,6 +31,16 @@ func SetBlobParams(codec codec.Codec, params blobtypes.Params) Modifier { } } +// SetSlashingParams will set the provided slashing params as genesis state. +func SetSlashingParams(codec codec.Codec, parans slashingtypes.Params) Modifier { + return func(state map[string]json.RawMessage) map[string]json.RawMessage { + slashingGenState := slashingtypes.DefaultGenesisState() + slashingGenState.Params = parans + state[slashingtypes.ModuleName] = codec.MustMarshalJSON(slashingGenState) + return state + } +} + // ImmediateProposals sets the thresholds for getting a gov proposal to very low // levels. func ImmediateProposals(codec codec.Codec) Modifier { diff --git a/test/util/test_app.go b/test/util/test_app.go index 7371d43e5e..afc8ff8820 100644 --- a/test/util/test_app.go +++ b/test/util/test_app.go @@ -31,8 +31,8 @@ import ( "github.com/celestiaorg/celestia-app/test/util/genesis" "github.com/cosmos/cosmos-sdk/crypto/hd" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/tendermint/tendermint/crypto/ed25519" tmversion "github.com/tendermint/tendermint/proto/tendermint/version" ) @@ -40,6 +40,8 @@ const ( ChainID = "test-app" ) +var GenesisTime = time.Date(2023, 1, 1, 1, 1, 1, 1, time.UTC).UTC() + // Get flags every time the simulator is run func init() { simapp.GetSimulatorFlags() @@ -75,11 +77,14 @@ func NewTestApp() *app.App { // SetupDeterministicGenesisState sets genesis on initialized testApp with the provided arguments. func SetupDeterministicGenesisState(testApp *app.App, pubKeys []cryptotypes.PubKey, balance int64, cparams *tmproto.ConsensusParams) (keyring.Keyring, []genesis.Account, error) { + slashingParams := slashingtypes.NewParams(2, sdk.OneDec(), time.Minute, sdk.OneDec(), sdk.OneDec()) + // Create genesis gen := genesis.NewDefaultGenesis(). WithChainID(ChainID). WithConsensusParams(cparams). - WithGenesisTime(time.Date(2023, 1, 1, 1, 1, 1, 1, time.UTC).UTC()) + WithModifiers(genesis.SetSlashingParams(testApp.AppCodec(), slashingParams)). + WithGenesisTime(GenesisTime) // Add accounts to genesis for _, pk := range pubKeys { @@ -93,7 +98,7 @@ func SetupDeterministicGenesisState(testApp *app.App, pubKeys []cryptotypes.PubK } // Add validator to genesis - err := AddDeterministicValidatorToGenesis(gen) + err := AddDeterministicValidatorsToGenesis(gen) if err != nil { return nil, nil, fmt.Errorf("failed to add validator: %w", err) } @@ -210,46 +215,44 @@ func SetupTestAppWithGenesisValSet(cparams *tmproto.ConsensusParams, genAccounts return testApp, kr } -// AddDeterministicValidatorToGenesis adds a single deterministic validator to the genesis. -func AddDeterministicValidatorToGenesis(g *genesis.Genesis) error { - // Hardcoded keys for deterministic account creation - mnemo := "body world north giggle crop reduce height copper damp next verify orphan lens loan adjust inform utility theory now ranch motion opinion crowd fun" - consensusKey := ed25519.GenPrivKeyFromSecret([]byte("12345678901234567890123456389012")) - networkKey := ed25519.GenPrivKeyFromSecret([]byte("12345678901234567890123456786012")) - - val := genesis.Validator{ - KeyringAccount: genesis.KeyringAccount{ - Name: "validator1", - InitialTokens: 1_000_000_000, - }, - Stake: 1_000_000, - ConsensusKey: consensusKey, - NetworkKey: networkKey, - } - - // Initialize the validator's genesis account in the keyring - rec, err := g.Keyring().NewAccount(val.Name, mnemo, "", "", hd.Secp256k1) - if err != nil { - return fmt.Errorf("failed to create account: %w", err) - } +func AddDeterministicValidatorsToGenesis(g *genesis.Genesis) error { + for i := range FixedMnemonics { + val := genesis.Validator{ + KeyringAccount: genesis.KeyringAccount{ + Name: "validator" + fmt.Sprint(i), + InitialTokens: 5_000_000_000, + }, + Stake: 1_000_000_000, + ConsensusKey: FixedConsensusPrivKeys[i], + NetworkKey: FixedNetWorkPrivKeys[i], + } + // initialize the validator's genesis account in the keyring + rec, err := g.Keyring().NewAccount(val.Name, FixedMnemonics[i], "", "", hd.Secp256k1) + if err != nil { + return fmt.Errorf("failed to create account: %w", err) + } - validatorPubKey, err := rec.GetPubKey() - if err != nil { - return fmt.Errorf("failed to get pubkey: %w", err) - } + validatorPubKey, err := rec.GetPubKey() + if err != nil { + return fmt.Errorf("failed to get pubkey: %w", err) + } - // Make account from keyring account - account := genesis.Account{ - PubKey: validatorPubKey, - Balance: val.KeyringAccount.InitialTokens, - } + // make account from keyring account + account := genesis.Account{ + PubKey: validatorPubKey, + Balance: val.KeyringAccount.InitialTokens, + } - // Add the validator's account to the genesis - if err := g.AddAccount(account); err != nil { - return fmt.Errorf("failed to add account: %w", err) + // add the validator's account to the genesis + if err := g.AddAccount(account); err != nil { + return fmt.Errorf("failed to add account: %w", err) + } + if err := g.AddValidator(val); err != nil { + return fmt.Errorf("failed to add validator: %w", err) + } } - return g.AddValidator(val) + return nil } // AddGenesisAccount mimics the cli addGenesisAccount command, providing an diff --git a/test/util/testfactory/common.go b/test/util/testfactory/common.go index bd6c77f309..93a953878d 100644 --- a/test/util/testfactory/common.go +++ b/test/util/testfactory/common.go @@ -62,3 +62,31 @@ func GetAddress(keys keyring.Keyring, account string) sdk.AccAddress { } return addr } + +func GetAddresses(keys keyring.Keyring) []sdk.AccAddress { + recs, err := keys.List() + if err != nil { + panic(err) + } + addresses := make([]sdk.AccAddress, 0, len(recs)) + for _, rec := range recs { + address, err := rec.GetAddress() + if err != nil { + panic(err) + } + addresses = append(addresses, address) + } + return addresses +} + +func GetAccountNames(keys keyring.Keyring) []string { + recs, err := keys.List() + if err != nil { + panic(err) + } + names := make([]string, 0, len(recs)) + for _, rec := range recs { + names = append(names, rec.Name) + } + return names +} From 03ac8e0af6e5a1faedea91cd6bf0b6f11cdb0610 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 23 Jul 2024 17:58:11 +0200 Subject: [PATCH 03/11] test: address review comments from another pr --- app/consistent_apphash_test.go | 72 +++++++++++++++++----------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index 754ce143fc..e8dfaf7b89 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -44,12 +44,13 @@ type BlobTx struct { txOptions []user.TxOption } -// TestConsistentAppHash executes all state machine messages, generates an app hash, -// and compares it against a previously generated hash from the same set of transactions. +// TestConsistentAppHash executes all state machine messages, generates an app hash and a data root, +// and compares it against a previously generated hashes from the same set of transactions. // App hashes across different commits should be consistent. func TestConsistentAppHash(t *testing.T) { // Expected app hash produced by v1.x - https://github.com/celestiaorg/celestia-app/blob/v1.x/app/consistent_apphash_test.go - // expectedAppHash := []byte{9, 208, 117, 101, 108, 61, 146, 58, 26, 190, 199, 124, 76, 178, 84, 74, 54, 159, 76, 187, 2, 169, 128, 87, 70, 78, 8, 192, 28, 144, 116, 117} + expectedDataRoot := []byte{100, 59, 112, 241, 238, 49, 50, 64, 105, 90, 209, 211, 49, 254, 211, 83, 133, 88, 5, 89, 221, 116, 141, 72, 33, 110, 16, 78, 5, 48, 118, 72} + expectedAppHash := []byte{84, 216, 210, 48, 113, 204, 234, 21, 150, 236, 97, 87, 242, 184, 45, 248, 116, 127, 49, 88, 134, 197, 202, 125, 44, 210, 67, 144, 107, 51, 145, 65} // Initialize testApp testApp := testutil.NewTestApp() @@ -99,6 +100,7 @@ func TestConsistentAppHash(t *testing.T) { // ----------- Create SDK Messages ------------ amount := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(1_000))) + // Minimum deposit required for a gov proposal to become active depositAmount := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(10000000000))) twoInt := sdk.NewInt(2) @@ -221,7 +223,7 @@ func TestConsistentAppHash(t *testing.T) { msgDelegate = stakingtypes.NewMsgDelegate(accountAddresses[0], genValidators[0].GetOperator(), amount[0]) secondBlockSdkMsgs = append(secondBlockSdkMsgs, msgDelegate) - // Messages are split in two blocks, this tx is part of the second block therefore the block height is incremented by 2 + // Block 2 height blockHeight := testApp.LastBlockHeight() + 2 // NewMsgCancelUnbondingDelegation - cancels unbonding delegation from validator-1 msgCancelUnbondingDelegation := stakingtypes.NewMsgCancelUnbondingDelegation(accountAddresses[0], genValidators[1].GetOperator(), blockHeight, amount[0]) @@ -245,7 +247,7 @@ func TestConsistentAppHash(t *testing.T) { // ------------ Third Block ------------ - // The transactions within the third block are signed by the validator's signer + // Txs within the third block are signed by the validator's signer var thirdBlockSdkMsgs []sdk.Msg // NewMsgWithdrawValidatorCommission - withdraws validator-0's commission @@ -260,13 +262,13 @@ func TestConsistentAppHash(t *testing.T) { // Create SDK transactions from the list of messages // and separate them into 3 different blocks - firstBlockRawTxs, err := processSdkMessages(signer, firstBlockSdkMsgs) + firstBlockEncodedTxs, err := processSdkMessages(signer, firstBlockSdkMsgs) require.NoError(t, err) - secondBlockRawTxs, err := processSdkMessages(signer, secondBlockSdkMsgs) + secondBlockEncodedTxs, err := processSdkMessages(signer, secondBlockSdkMsgs) require.NoError(t, err) - validatorRawTxs, err := processSdkMessages(valSigner, thirdBlockSdkMsgs) + thirdBlockEncodedTxs, err := processSdkMessages(valSigner, thirdBlockSdkMsgs) require.NoError(t, err) // Create a Blob Tx @@ -275,30 +277,29 @@ func TestConsistentAppHash(t *testing.T) { blobs: []*tmproto.Blob{New(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion)}, txOptions: blobfactory.DefaultTxOpts(), } - rawBlobTx, _, err := signer.CreatePayForBlobs(blobTx.author, blobTx.blobs, blobTx.txOptions...) + encodedBlobTx, _, err := signer.CreatePayForBlobs(blobTx.author, blobTx.blobs, blobTx.txOptions...) require.NoError(t, err) - // Convert validators to abci validators + // Convert validators to ABCI validators abciValidators, err := convertToABCIValidators(genValidators) require.NoError(t, err) // Execute the first block - _, firstBlockCommitHash, err := executeTxs(testApp, []byte{}, firstBlockRawTxs, abciValidators, testApp.LastCommitID().Hash) + _, firstBlockAppHash, err := executeTxs(testApp, []byte{}, firstBlockEncodedTxs, abciValidators, testApp.LastCommitID().Hash) require.NoError(t, err) // Execute the second block - _, secondAppHash, err := executeTxs(testApp, rawBlobTx, secondBlockRawTxs, abciValidators, firstBlockCommitHash) + _, secondBlockAppHash, err := executeTxs(testApp, encodedBlobTx, secondBlockEncodedTxs, abciValidators, firstBlockAppHash) require.NoError(t, err) - // Execute the final block and get the data hash alongside the final app hash - dataHash, finalAppHash, err := executeTxs(testApp, []byte{}, validatorRawTxs, abciValidators, secondAppHash) + // Execute the final block and get the data root alongside the final app hash + finalDataRoot, finalAppHash, err := executeTxs(testApp, []byte{}, thirdBlockEncodedTxs, abciValidators, secondBlockAppHash) require.NoError(t, err) - fmt.Println(finalAppHash, "APP HASH") - fmt.Println(dataHash, "DATA HASH") - // Require that the app hash is equal to the app hash produced on a different commit - // require.Equal(t, expectedAppHash, appHash) + require.Equal(t, expectedAppHash, finalAppHash) + // Require that the data root is equal to the data root produced on a different commit + require.Equal(t, expectedDataRoot, finalDataRoot) } // fixedNamespace returns a hardcoded namespace @@ -341,11 +342,11 @@ func deterministicKeyRing(cdc codec.Codec) (keyring.Keyring, []types.PubKey) { } // processSdkMessages takes a list of sdk messages, forms transactions, signs them -// and returns a list of raw transactions +// and returns a list of encoded transactions func processSdkMessages(signer *user.TxSigner, sdkMessages []sdk.Msg) ([][]byte, error) { - rawSdkTxs := make([][]byte, 0, len(sdkMessages)) + encodedSdkTxs := make([][]byte, 0, len(sdkMessages)) for _, msg := range sdkMessages { - rawSdkTx, err := signer.CreateTx([]sdk.Msg{msg}, blobfactory.DefaultTxOpts()...) + encodedSdkTx, err := signer.CreateTx([]sdk.Msg{msg}, blobfactory.DefaultTxOpts()...) if err != nil { return nil, err } @@ -357,33 +358,34 @@ func processSdkMessages(signer *user.TxSigner, sdkMessages []sdk.Msg) ([][]byte, return nil, err } - rawSdkTxs = append(rawSdkTxs, rawSdkTx) + encodedSdkTxs = append(encodedSdkTxs, encodedSdkTx) } - return rawSdkTxs, nil + return encodedSdkTxs, nil } // executeTxs executes a set of transactions and returns the data hash and app hash -func executeTxs(testApp *app.App, rawBlobTx []byte, rawSdkTxs [][]byte, validators []abci.Validator, lastCommitHash []byte) ([]byte, []byte, error) { +func executeTxs(testApp *app.App, encodedBlobTx []byte, encodedSdkTxs [][]byte, validators []abci.Validator, lastCommitHash []byte) ([]byte, []byte, error) { height := testApp.LastBlockHeight() + 1 chainID := testApp.GetChainID() genesisTime := testutil.GenesisTime // Prepare Proposal - resPrePareProposal := testApp.PrepareProposal(abci.RequestPrepareProposal{ + resPrepareProposal := testApp.PrepareProposal(abci.RequestPrepareProposal{ BlockData: &tmproto.Data{ - Txs: rawSdkTxs, + Txs: encodedSdkTxs, }, ChainId: chainID, Height: height, - Time: genesisTime.Add(time.Duration(height) * time.Minute), + // Dynamically increase time so the validator can be unjailed (1m duration) + Time: genesisTime.Add(time.Duration(height) * time.Minute), }) - dataHash := resPrePareProposal.BlockData.Hash + dataHash := resPrepareProposal.BlockData.Hash header := tmproto.Header{ Version: version.Consensus{App: 1}, - DataHash: resPrePareProposal.BlockData.Hash, + DataHash: resPrepareProposal.BlockData.Hash, ChainID: chainID, Time: genesisTime.Add(time.Duration(height) * time.Minute), Height: height, @@ -392,7 +394,7 @@ func executeTxs(testApp *app.App, rawBlobTx []byte, rawSdkTxs [][]byte, validato // Process Proposal resProcessProposal := testApp.ProcessProposal(abci.RequestProcessProposal{ - BlockData: resPrePareProposal.BlockData, + BlockData: resPrepareProposal.BlockData, Header: header, }, ) @@ -421,17 +423,17 @@ func executeTxs(testApp *app.App, rawBlobTx []byte, rawSdkTxs [][]byte, validato }) // Deliver SDK Txs - for i, rawSdkTx := range rawSdkTxs { - resp := testApp.DeliverTx(abci.RequestDeliverTx{Tx: rawSdkTx}) - if resp.Code != uint32(0) { + for i, tx := range encodedSdkTxs { + resp := testApp.DeliverTx(abci.RequestDeliverTx{Tx: tx}) + if resp.Code != abci.CodeTypeOK { return nil, nil, fmt.Errorf("DeliverTx failed for the message at index %d: %s", i, resp.Log) } } // Deliver Blob Txs - if len(rawBlobTx) != 0 { + if len(encodedBlobTx) != 0 { // Deliver Blob Tx - blob, isBlobTx := coretypes.UnmarshalBlobTx(rawBlobTx) + blob, isBlobTx := coretypes.UnmarshalBlobTx(encodedBlobTx) if !isBlobTx { return nil, nil, fmt.Errorf("Not a valid BlobTx") } From 33e5edaced46bda269c825755773a40c042ad318 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 23 Jul 2024 18:50:03 +0200 Subject: [PATCH 04/11] test: update the comment --- app/consistent_apphash_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index e8dfaf7b89..6b91f81340 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -48,7 +48,7 @@ type BlobTx struct { // and compares it against a previously generated hashes from the same set of transactions. // App hashes across different commits should be consistent. func TestConsistentAppHash(t *testing.T) { - // Expected app hash produced by v1.x - https://github.com/celestiaorg/celestia-app/blob/v1.x/app/consistent_apphash_test.go + // App hash and data root generated from executing txs on this branch expectedDataRoot := []byte{100, 59, 112, 241, 238, 49, 50, 64, 105, 90, 209, 211, 49, 254, 211, 83, 133, 88, 5, 89, 221, 116, 141, 72, 33, 110, 16, 78, 5, 48, 118, 72} expectedAppHash := []byte{84, 216, 210, 48, 113, 204, 234, 21, 150, 236, 97, 87, 242, 184, 45, 248, 116, 127, 49, 88, 134, 197, 202, 125, 44, 210, 67, 144, 107, 51, 145, 65} From 6edf42fbfc9c72677899dcd90d051ebcda609370 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 23 Jul 2024 18:51:41 +0200 Subject: [PATCH 05/11] style: make linter happy --- app/consistent_apphash_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index 6b91f81340..1a0cfcaec9 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -50,7 +50,7 @@ type BlobTx struct { func TestConsistentAppHash(t *testing.T) { // App hash and data root generated from executing txs on this branch expectedDataRoot := []byte{100, 59, 112, 241, 238, 49, 50, 64, 105, 90, 209, 211, 49, 254, 211, 83, 133, 88, 5, 89, 221, 116, 141, 72, 33, 110, 16, 78, 5, 48, 118, 72} - expectedAppHash := []byte{84, 216, 210, 48, 113, 204, 234, 21, 150, 236, 97, 87, 242, 184, 45, 248, 116, 127, 49, 88, 134, 197, 202, 125, 44, 210, 67, 144, 107, 51, 145, 65} + expectedAppHash := []byte{84, 216, 210, 48, 113, 204, 234, 21, 150, 236, 97, 87, 242, 184, 45, 248, 116, 127, 49, 88, 134, 197, 202, 125, 44, 210, 67, 144, 107, 51, 145, 65} // Initialize testApp testApp := testutil.NewTestApp() From 6784819036bfcc03ba2c00aaea76c340157fe8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nina=20/=20=E1=83=9C=E1=83=98=E1=83=9C=E1=83=90?= Date: Wed, 24 Jul 2024 11:32:21 +0200 Subject: [PATCH 06/11] Update app/consistent_apphash_test.go Co-authored-by: Rootul P --- app/consistent_apphash_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index 1a0cfcaec9..a21582ed7f 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -45,7 +45,7 @@ type BlobTx struct { } // TestConsistentAppHash executes all state machine messages, generates an app hash and a data root, -// and compares it against a previously generated hashes from the same set of transactions. +// and compares it against previously generated hashes from the same set of transactions. // App hashes across different commits should be consistent. func TestConsistentAppHash(t *testing.T) { // App hash and data root generated from executing txs on this branch From a4d0c0417fb91ab9ab04883c95389bd9fd0a3f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nina=20/=20=E1=83=9C=E1=83=98=E1=83=9C=E1=83=90?= Date: Wed, 24 Jul 2024 11:32:30 +0200 Subject: [PATCH 07/11] Update app/consistent_apphash_test.go Co-authored-by: Rootul P --- app/consistent_apphash_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index a21582ed7f..4b27ef604b 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -12,7 +12,6 @@ import ( testutil "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" From 03bd5a55cf51eff69ed410fb05614cacf1af6cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nina=20/=20=E1=83=9C=E1=83=98=E1=83=9C=E1=83=90?= Date: Wed, 24 Jul 2024 11:32:40 +0200 Subject: [PATCH 08/11] Update app/consistent_apphash_test.go Co-authored-by: Rootul P --- app/consistent_apphash_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index 4b27ef604b..acc75e92a5 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -18,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" From 61fa43fb8cf5d8ce9d9fe7166d9a1eee66e93f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nina=20/=20=E1=83=9C=E1=83=98=E1=83=9C=E1=83=90?= Date: Wed, 24 Jul 2024 11:32:49 +0200 Subject: [PATCH 09/11] Update app/consistent_apphash_test.go Co-authored-by: Rootul P --- app/consistent_apphash_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index acc75e92a5..00bb9763f5 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -428,7 +428,7 @@ func executeTxs(testApp *app.App, encodedBlobTx []byte, encodedSdkTxs [][]byte, } } - // Deliver Blob Txs + // Deliver Blob Tx if len(encodedBlobTx) != 0 { // Deliver Blob Tx blob, isBlobTx := coretypes.UnmarshalBlobTx(encodedBlobTx) From 94b3d4f00b9557daf9a254bde1183dcdc442de4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nina=20/=20=E1=83=9C=E1=83=98=E1=83=9C=E1=83=90?= Date: Wed, 24 Jul 2024 11:32:56 +0200 Subject: [PATCH 10/11] Update app/consistent_apphash_test.go Co-authored-by: Rootul P --- app/consistent_apphash_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index 00bb9763f5..75bced53ca 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -27,7 +27,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" From 1f9abcdb1804fe97e064f43e34471f41c06d533e Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 24 Jul 2024 11:49:02 +0200 Subject: [PATCH 11/11] style: lint --- app/consistent_apphash_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/consistent_apphash_test.go b/app/consistent_apphash_test.go index 75bced53ca..29acd448b0 100644 --- a/app/consistent_apphash_test.go +++ b/app/consistent_apphash_test.go @@ -8,17 +8,18 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" + appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/user" testutil "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" + blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" crisisTypes "github.com/cosmos/cosmos-sdk/x/crisis/types" @@ -27,7 +28,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types"