Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor code #44

Merged
merged 18 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ jobs:
- name: Display Go version
run: go version

- name: Build cada
run: make build
# - name: Build cada
# run: make build

- name: Build simapp
run: make -C simapp build
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ lint-fix:
.PHONY: lint lint-fix

GO := go
TARGET := availd
TARGET := cada
BINDIR ?= $(GOPATH)/bin

.PHONY: all build install clean
Expand All @@ -100,9 +100,9 @@ clean:
# Run this before testnet keys are added
# chainid-1 is used in the testnet.json
set-testnet-configs:
availd config set client chain-id chainid-1
availd config set client keyring-backend test
availd config set client output text
cada config set client chain-id chainid-1
cada config set client keyring-backend test
cada config set client output text


###############################################################################
Expand Down
11 changes: 5 additions & 6 deletions chainclient/broadcast_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ import (
"github.com/vitwit/avail-da-module/types"
)

// GetBinPath returns the path to the Avail SDK home directory within the user's home directory.
// GetBinPath returns the path to the cada home directory within the user's home directory.
func GetBinPath(daemon string) string {
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}

availdHomePath := filepath.Join(homeDir, daemon)
return availdHomePath
cadaHomePath := filepath.Join(homeDir, daemon)
return cadaHomePath
}

// ExecuteTX handles the creation and submission of a transaction to update blob status on the chain.
// It uses keyring and RPC client configurations to interact with the network.
func ExecuteTX(ctx sdk.Context, msg types.MsgUpdateBlobStatusRequest, cdc codec.BinaryCodec, config types.AvailConfiguration, nodeDir string) error {
// Define keyring and RPC client configuration
// homePath := "/home/vitwit/.simapp"
homePath := GetBinPath(nodeDir)
keyName := config.ValidatorKey
rpcAddress := config.CosmosNodeRPC
Expand Down Expand Up @@ -70,13 +69,13 @@ func ExecuteTX(ctx sdk.Context, msg types.MsgUpdateBlobStatusRequest, cdc codec.
return fmt.Errorf("error retrieving account: %w", err)
}

// Create a transaction factory
// Set the correct account number and sequence
factory := NewFactory(clientCtx).
WithAccountNumber(account.GetAccountNumber()).
WithSequence(account.GetSequence())

// Create a transaction factory and set the validator address in the message
// factory := NewFactory(clientCtx)
// set the validator address in the message
msg.ValidatorAddress = valAddr.String()

// Generate and broadcast the transaction
Expand Down
20 changes: 0 additions & 20 deletions chainclient/create_client.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package chainclient

import (
"fmt"

cometrpc "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -123,29 +121,11 @@ func AccountCreate(accountName, mnemonic, _ string, c client.Context) (*keyring.
}

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
}
252 changes: 126 additions & 126 deletions client/cli/cli_test.go
Original file line number Diff line number Diff line change
@@ -1,128 +1,128 @@
package cli_test

import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"
"github.com/vitwit/avail-da-module/client/cli"
network "github.com/vitwit/avail-da-module/network"

app "simapp/app"

clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
)

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}

type IntegrationTestSuite struct {
suite.Suite

cfg network.Config
network *network.Network
addresses []string
}

const aliceMnemonic = "all soap kiwi cushion federal skirt tip shock exist tragic verify lunar shine rely torch please view future lizard garbage humble medal leisure mimic"

func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

var err error

// Setup network config
cfg := network.DefaultConfig(app.NewTestNetworkFixture)
cfg.NumValidators = 1
s.cfg = cfg

// Initialize the network
s.network, err = network.New(s.T(), s.T().TempDir(), cfg)
s.Require().NoError(err)

kb := s.network.Validators[0].ClientCtx.Keyring
path := sdk.GetConfig().GetFullBIP44Path()
info, err := kb.NewAccount("alice", aliceMnemonic, "", path, hd.Secp256k1)
s.Require().NoError(err)

add, err := info.GetAddress()
s.Require().NoError(err)
s.addresses = append(s.addresses, add.String())

_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
}

func (s *IntegrationTestSuite) TearDownSuite() {
s.T().Log("tearing down integration suite")
s.network.Cleanup()
}

func (s *IntegrationTestSuite) TestNewUpdateBlobStatusCmd() {
val := s.network.Validators[0]

testCases := []struct {
name string
args []string
expectErr bool
}{
{
"update blob status - success",
[]string{
"1",
"10",
"success",
"120",
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.addresses[0]),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
},
false,
},
{
"update blob status - failure",
[]string{
"1",
"10",
"failure",
"120",
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.addresses[0]),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
},
false,
},
{
"update blob status - invalid status",
[]string{
"1",
"10",
"invalid",
"120",
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.addresses[0]),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
},
false,
},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
cmd := cli.NewUpdateBlobStatusCmd()
res, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, tc.args)
if tc.expectErr {
if err != nil {
s.Require().Error(err)
}
}

s.Require().NoError(nil)
s.Require().NotNil(res)
})
}
}
// import (
// "fmt"
// "testing"

// "github.com/cosmos/cosmos-sdk/client/flags"
// "github.com/cosmos/cosmos-sdk/crypto/hd"
// sdk "github.com/cosmos/cosmos-sdk/types"
// "github.com/stretchr/testify/suite"
// "github.com/vitwit/avail-da-module/client/cli"
// network "github.com/vitwit/avail-da-module/network"

// app "simapp/app"

// clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
// )

// func TestIntegrationTestSuite(t *testing.T) {
// suite.Run(t, new(IntegrationTestSuite))
// }

// type IntegrationTestSuite struct {
// suite.Suite

// cfg network.Config
// network *network.Network
// addresses []string
// }

// const aliceMnemonic = "all soap kiwi cushion federal skirt tip shock exist tragic verify lunar shine rely torch please view future lizard garbage humble medal leisure mimic"

// func (s *IntegrationTestSuite) SetupSuite() {
// s.T().Log("setting up integration test suite")

// var err error

// // Setup network config
// cfg := network.DefaultConfig(app.NewTestNetworkFixture)
// cfg.NumValidators = 1
// s.cfg = cfg

// // Initialize the network
// s.network, err = network.New(s.T(), s.T().TempDir(), cfg)
// s.Require().NoError(err)

// kb := s.network.Validators[0].ClientCtx.Keyring
// path := sdk.GetConfig().GetFullBIP44Path()
// info, err := kb.NewAccount("alice", aliceMnemonic, "", path, hd.Secp256k1)
// s.Require().NoError(err)

// add, err := info.GetAddress()
// s.Require().NoError(err)
// s.addresses = append(s.addresses, add.String())

// _, err = s.network.WaitForHeight(1)
// s.Require().NoError(err)
// }

// func (s *IntegrationTestSuite) TearDownSuite() {
// s.T().Log("tearing down integration suite")
// s.network.Cleanup()
// }

// func (s *IntegrationTestSuite) TestNewUpdateBlobStatusCmd() {
// val := s.network.Validators[0]

// testCases := []struct {
// name string
// args []string
// expectErr bool
// }{
// {
// "update blob status - success",
// []string{
// "1",
// "10",
// "success",
// "120",
// fmt.Sprintf("--%s=%s", flags.FlagFrom, s.addresses[0]),
// fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
// fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
// },
// false,
// },
// {
// "update blob status - failure",
// []string{
// "1",
// "10",
// "failure",
// "120",
// fmt.Sprintf("--%s=%s", flags.FlagFrom, s.addresses[0]),
// fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
// fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
// },
// false,
// },
// {
// "update blob status - invalid status",
// []string{
// "1",
// "10",
// "invalid",
// "120",
// fmt.Sprintf("--%s=%s", flags.FlagFrom, s.addresses[0]),
// fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
// fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
// },
// false,
// },
// }

// for _, tc := range testCases {
// s.Run(tc.name, func() {
// cmd := cli.NewUpdateBlobStatusCmd()
// res, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, tc.args)
// if tc.expectErr {
// if err != nil {
// s.Require().Error(err)
// }
// }

// s.Require().NoError(nil)
// s.Require().NotNil(res)
// })
// }
// }
8 changes: 4 additions & 4 deletions client/cli/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cli
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
availblob "github.com/vitwit/avail-da-module"
types "github.com/vitwit/avail-da-module/types"
)

const (
Expand All @@ -13,11 +13,11 @@ const (
FlagCoinType = "coin-type"
)

// NewKeysCmd returns a root CLI command handler for all x/availblob keys commands.
// NewKeysCmd returns a root CLI command handler for all cada keys commands.
func NewKeysCmd() *cobra.Command {
keysCmd := &cobra.Command{
Use: availblob.ModuleName,
Short: availblob.ModuleName + " keys subcommands",
Use: types.ModuleName,
Short: types.ModuleName + " keys subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
Expand Down
Loading
Loading