diff --git a/keeper/client.go b/keeper/client.go deleted file mode 100644 index 3f14e36..0000000 --- a/keeper/client.go +++ /dev/null @@ -1,180 +0,0 @@ -package keeper - -// import ( -// "fmt" - -// cometrpc "github.com/cometbft/cometbft/rpc/client/http" -// "github.com/cosmos/cosmos-sdk/client" -// "github.com/cosmos/cosmos-sdk/client/flags" -// "github.com/cosmos/cosmos-sdk/client/tx" -// "github.com/cosmos/cosmos-sdk/codec" -// codectypes "github.com/cosmos/cosmos-sdk/codec/types" -// "github.com/cosmos/cosmos-sdk/crypto/hd" -// "github.com/cosmos/cosmos-sdk/crypto/keyring" -// "github.com/cosmos/cosmos-sdk/std" -// sdk "github.com/cosmos/cosmos-sdk/types" -// "github.com/cosmos/cosmos-sdk/types/tx/signing" -// authTx "github.com/cosmos/cosmos-sdk/x/auth/tx" -// authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" -// "github.com/cosmos/go-bip39" - -// // "github.com/tendermint/starport/starport/pkg/xfilepath" - -// "github.com/cosmos/cosmos-sdk/types/module" -// ) - -// const ( -// defaultGasAdjustment = 1.0 -// defaultGasLimit = 300000 -// ) - -// // var availdHomePath = xfilepath.JoinFromHome(xfilepath.Path("availsdk")) - -// func NewClientCtx(kr keyring.Keyring, c *cometrpc.HTTP, chainID string, -// cdc codec.BinaryCodec, homepath string, fromAddress sdk.AccAddress) client.Context { -// encodingConfig := MakeEncodingConfig() - -// broadcastMode := flags.BroadcastSync - -// // homepath := "/home/vitwit/.availsdk" - -// return client.Context{}. -// WithCodec(cdc.(codec.Codec)). -// WithChainID(chainID). -// WithFromAddress(fromAddress). -// WithFromName("testkey"). -// WithKeyringDir(homepath). -// WithBroadcastMode(broadcastMode). -// WithTxConfig(authTx.NewTxConfig(cdc.(codec.Codec), authTx.DefaultSignModes)). -// WithKeyring(kr). -// WithAccountRetriever(authtypes.AccountRetriever{}). -// WithClient(c).WithInterfaceRegistry(encodingConfig.InterfaceRegistry). -// WithSkipConfirmation(true) -// } - -// // NewFactory creates a new Factory. -// func NewFactory(clientCtx client.Context) tx.Factory { -// return tx.Factory{}. -// WithChainID(clientCtx.ChainID). -// WithKeybase(clientCtx.Keyring). -// WithGas(defaultGasLimit). -// WithGasAdjustment(defaultGasAdjustment). -// WithSignMode(signing.SignMode_SIGN_MODE_DIRECT). -// WithAccountRetriever(clientCtx.AccountRetriever). -// WithTxConfig(clientCtx.TxConfig) -// } - -// // MakeEncodingConfig creates an EncodingConfig for an amino based test configuration. -// func MakeEncodingConfig(modules ...module.AppModuleBasic) EncodingConfig { -// aminoCodec := codec.NewLegacyAmino() -// interfaceRegistry := codectypes.NewInterfaceRegistry() -// codec := codec.NewProtoCodec(interfaceRegistry) -// txCfg := authTx.NewTxConfig(codec, authTx.DefaultSignModes) - -// encCfg := EncodingConfig{ -// InterfaceRegistry: interfaceRegistry, -// Codec: codec, -// TxConfig: txCfg, -// Amino: aminoCodec, -// } - -// mb := module.NewBasicManager(modules...) - -// std.RegisterLegacyAminoCodec(encCfg.Amino) -// std.RegisterInterfaces(encCfg.InterfaceRegistry) -// mb.RegisterLegacyAminoCodec(encCfg.Amino) -// mb.RegisterInterfaces(encCfg.InterfaceRegistry) - -// return encCfg -// } - -// // func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig { -// // aminoCodec := codec.NewLegacyAmino() -// // interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() -// // codec := codec.NewProtoCodec(interfaceRegistry) - -// // encCfg := TestEncodingConfig{ -// // InterfaceRegistry: interfaceRegistry, -// // Codec: codec, -// // TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes), -// // Amino: aminoCodec, -// // } - -// // mb := module.NewBasicManager(modules...) - -// // std.RegisterLegacyAminoCodec(encCfg.Amino) -// // std.RegisterInterfaces(encCfg.InterfaceRegistry) -// // mb.RegisterLegacyAminoCodec(encCfg.Amino) -// // mb.RegisterInterfaces(encCfg.InterfaceRegistry) - -// // return encCfg -// // } - -// // EncodingConfig specifies the concrete encoding types to use for a given app. -// // This is provided for compatibility between protobuf and amino implementations. -// type EncodingConfig struct { -// InterfaceRegistry codectypes.InterfaceRegistry -// Codec codec.Codec -// TxConfig client.TxConfig -// Amino *codec.LegacyAmino -// } - -// // ImportMnemonic is to import existing account mnemonic in keyring -// func ImportMnemonic(keyName, mnemonic, hdPath string, c client.Context) (*keyring.Record, error) { -// info, err := AccountCreate(keyName, mnemonic, hdPath, c) // return account also -// // fmt.Println("here the accc details.......", keyName, mnemonic, hdPath) -// if err != nil { -// return nil, err -// } - -// return info, nil -// } - -// // AccountCreate creates an account by name and mnemonic (optional) in the keyring. -// func AccountCreate(accountName, mnemonic, hdPath string, c client.Context) (*keyring.Record, error) { -// if mnemonic == "" { -// entropySeed, err := bip39.NewEntropy(256) -// if err != nil { -// return nil, err -// } -// mnemonic, err = bip39.NewMnemonic(entropySeed) -// fmt.Println("mnemoniccccc here.....", mnemonic) -// if err != nil { -// return nil, err -// } -// } - -// algos, _ := c.Keyring.SupportedAlgorithms() -// algo, err := keyring.NewSigningAlgoFromString(string(hd.Secp256k1Type), algos) -// if err != nil { -// return nil, err -// } - -// path := hd.CreateHDPath(118, 0, 0).String() -// // fmt.Println("pathhh......", path) - -// // record, str, err := c.Keyring.NewMnemonic("test_key1", keyring.English, path, keyring.DefaultBIP39Passphrase, hd.Secp256k1) -// // fmt.Println("recorddddd.......", err, str, record) - -// // k, _, err = kb.NewMnemonic("test", English, types.FullFundraiserPath, DefaultBIP39Passphrase, hd.Secp256k1) -// info, err := c.Keyring.NewAccount(accountName, mnemonic, keyring.DefaultBIP39Passphrase, path, algo) -// fmt.Println("after creationnnn.........", info, err) -// if err != nil { -// return nil, err -// } -// // pk, err := info.GetPubKey() -// // if err != nil { -// // return nil, err -// // } - -// // addr := sdk.AccAddress(pk.Address()) -// // fmt.Println("address hereee...", addr) - -// // aa, err := info.GetAddress() -// // fmt.Println("here aa and err.......", aa, err) - -// // account := c.ToAccount(info) -// // account.Mnemonic = mnemonic -// return info, nil -// // return nil -// } diff --git a/keeper/keeper_test.go b/keeper/keeper_test.go index 12f621a..215e56b 100644 --- a/keeper/keeper_test.go +++ b/keeper/keeper_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/suite" cada "github.com/vitwit/avail-da-module" "github.com/vitwit/avail-da-module/keeper" - mocks "github.com/vitwit/avail-da-module/keeper/mocks" module "github.com/vitwit/avail-da-module/module" "github.com/vitwit/avail-da-module/types" ) @@ -40,7 +39,6 @@ type TestSuite struct { encCfg moduletestutil.TestEncodingConfig addressCodec addresstypes.Codec baseApp *baseapp.BaseApp - mockKeeper *mocks.MockKeeper appOpts servertypes.AppOptions app *cadaApp.ChainApp upgradeKeeper upgradekeeper.Keeper @@ -57,7 +55,6 @@ func TestKeeperTestSuite(t *testing.T) { func (s *TestSuite) SetupTest() { key := storetypes.NewKVStoreKey(cada.ModuleName) - s.mockKeeper = new(mocks.MockKeeper) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()}) diff --git a/keeper/mocks/mock_keeper.go b/keeper/mocks/mock_keeper.go deleted file mode 100644 index de8de3b..0000000 --- a/keeper/mocks/mock_keeper.go +++ /dev/null @@ -1,28 +0,0 @@ -package mocks - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/mock" - "github.com/vitwit/avail-da-module/types" -) - -type MockKeeper struct { - mock.Mock -} - -func (m *MockKeeper) SubmitBlob(ctx sdk.Context, req *types.MsgSubmitBlobRequest) { - m.Called(ctx, req) -} - -type MockKVStore struct { - mock.Mock -} - -func (m *MockKVStore) Get(key []byte) []byte { - args := m.Called(key) - return args.Get(0).([]byte) -} - -func (m *MockKVStore) Set(key, value []byte) { - m.Called(key, value) -} diff --git a/keeper/msg_server_test.go b/keeper/msg_server_test.go index ac5432d..aa40e54 100644 --- a/keeper/msg_server_test.go +++ b/keeper/msg_server_test.go @@ -12,16 +12,14 @@ func (s *TestSuite) TestMsgServer_UpdateBlobStatus() { err = availkeeper.UpdateEndHeight(s.ctx, s.store, uint64(20)) s.Require().NoError(err) - availkeeper.UpdateBlobStatus(s.ctx, s.store, uint32(1)) - s.Require().NoError(err) - testCases := []struct { name string inputMsg *types.MsgUpdateBlobStatusRequest + status uint32 expectErr bool }{ { - "submit blob request", + "update blob status", &types.MsgUpdateBlobStatusRequest{ ValidatorAddress: s.addrs[1].String(), BlocksRange: &types.Range{ @@ -31,12 +29,58 @@ func (s *TestSuite) TestMsgServer_UpdateBlobStatus() { AvailHeight: 20, IsSuccess: true, }, + 1, false, }, + { + "status is not in pending", + &types.MsgUpdateBlobStatusRequest{ + ValidatorAddress: s.addrs[1].String(), + BlocksRange: &types.Range{ + From: 11, + To: 20, + }, + AvailHeight: 20, + IsSuccess: true, + }, + 3, + true, + }, + { + "data posting is not succeeded", + &types.MsgUpdateBlobStatusRequest{ + ValidatorAddress: s.addrs[1].String(), + BlocksRange: &types.Range{ + From: 11, + To: 20, + }, + AvailHeight: 20, + IsSuccess: false, + }, + 1, + false, + }, + { + "invalid blocks range", + &types.MsgUpdateBlobStatusRequest{ + ValidatorAddress: s.addrs[1].String(), + BlocksRange: &types.Range{ + From: 12, + To: 20, + }, + AvailHeight: 20, + IsSuccess: true, + }, + 1, + true, + }, } for _, tc := range testCases { s.Run(tc.name, func() { + availkeeper.UpdateBlobStatus(s.ctx, s.store, tc.status) + s.Require().NoError(err) + _, err := s.msgserver.UpdateBlobStatus(s.ctx, tc.inputMsg) if tc.expectErr { s.Require().Error(err) @@ -46,100 +90,3 @@ func (s *TestSuite) TestMsgServer_UpdateBlobStatus() { }) } } - -// func (s *TestSuite) TestUpdateBlobStatus() { - -// testCases := []struct { -// name string -// inputMsg *types.MsgUpdateBlobStatusRequest -// provenHeight uint64 -// endHeight uint64 -// status uint32 -// expectErr bool -// }{ -// { -// "update blob status", -// &types.MsgUpdateBlobStatusRequest{ -// ValidatorAddress: s.addrs[1].String(), -// BlocksRange: &types.Range{ -// From: 11, -// To: 20, -// }, -// AvailHeight: 20, -// IsSuccess: true, -// }, -// 10, -// 20, -// 1, -// false, -// }, -// { -// "submit invalid block range request", -// &types.MsgUpdateBlobStatusRequest{ -// ValidatorAddress: s.addrs[1].String(), -// BlocksRange: &types.Range{ -// From: 11, -// To: 20, -// }, -// AvailHeight: 20, -// IsSuccess: true, -// }, -// 10, -// 15, -// 1, -// true, -// }, -// { -// "status is not in pending state", -// &types.MsgUpdateBlobStatusRequest{ -// ValidatorAddress: s.addrs[1].String(), -// BlocksRange: &types.Range{ -// From: 11, -// To: 20, -// }, -// AvailHeight: 20, -// IsSuccess: true, -// }, -// 10, -// 20, -// 3, -// true, -// }, -// { -// "update blob status request is not success", -// &types.MsgUpdateBlobStatusRequest{ -// ValidatorAddress: s.addrs[1].String(), -// BlocksRange: &types.Range{ -// From: 11, -// To: 20, -// }, -// AvailHeight: 20, -// IsSuccess: false, -// }, -// 10, -// 20, -// 1, -// false, -// }, -// } - -// for _, tc := range testCases { -// s.Run(tc.name, func() { -// err := s.keeper.SetProvenHeight(s.ctx, tc.provenHeight) -// s.Require().NoError(err) - -// err = availkeeper.UpdateEndHeight(s.ctx, s.store, tc.endHeight) -// s.Require().NoError(err) - -// availkeeper.UpdateBlobStatus(s.ctx, s.store, tc.status) -// s.Require().NoError(err) - -// err = store.UpdateBlobStatus(s.ctx, s.store, tc.status) -// if tc.expectErr { -// s.Require().Error(err) -// } else { -// s.Require().NoError(err) -// } -// }) -// } -// } diff --git a/keeper/status_test.go b/keeper/status_test.go index 0f83c5e..02dada3 100644 --- a/keeper/status_test.go +++ b/keeper/status_test.go @@ -32,3 +32,34 @@ func (s *TestSuite) TestSetBlobStatusPending() { }) } } + +func (s *TestSuite) TestSetBlobStatus() { + + testCases := []struct { + name string + startHeight uint64 + endHeight uint64 + status uint32 + expectErr bool + }{ + { + "set blob status as pending", + 10, + 20, + 0, + false, + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + sErr := s.keeper.SetBlobStatus(s.ctx, tc.status) + status, err := s.queryClient.SubmittedBlobStatus(s.ctx, &types.QuerySubmittedBlobStatusRequest{}) + s.Require().NoError(err) + if tc.expectErr { + s.Require().NoError(sErr) + s.Require().Equal(status.Status, "READY_STATE") + } + }) + } +} diff --git a/relayer/process_blob.go b/relayer/process_blob.go deleted file mode 100644 index 38435d6..0000000 --- a/relayer/process_blob.go +++ /dev/null @@ -1,28 +0,0 @@ -package relayer - -import ( - "fmt" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/spf13/cobra" - "github.com/vitwit/avail-da-module/types" -) - -func (r *Relayer) StartBlobLifeCycle(msg types.MsgSubmitBlobRequest, cmd *cobra.Command) { - - fmt.Println("inside like cycle.................", msg, cmd == nil) - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - fmt.Println("error in start blob life cycle", err) - return - } - - msg.ValidatorAddress = clientCtx.GetFromAddress().String() - err = tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) - if err != nil { - fmt.Println("error in start blob life cycle", err) - return - } - fmt.Println("broadcast success..........") -}