diff --git a/lib/lib.go b/lib/lib.go index 3e19ed3..f1a93f5 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -14,6 +14,7 @@ import ( "time" "github.com/BurntSushi/toml" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/somatic-labs/hardhat/types" ) @@ -141,3 +142,17 @@ func GenerateRandomStringOfLength(n int) (string, error) { } return string(b), nil } + +func GenerateRandomAccount(prefix string) (sdk.AccAddress, error) { + // Generate 20 random bytes + randomBytes := make([]byte, 20) + _, err := rand.Read(randomBytes) + if err != nil { + return nil, err + } + + // Create an AccAddress from the random bytes + accAddress := sdk.AccAddress(randomBytes) + + return accAddress, nil +} diff --git a/main.go b/main.go index dceb8ce..26ca152 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,9 @@ func main() { } nodeURL := nodes[0] // Use only the first node + if nodeURL == "" { + log.Fatal("Node URL is empty. Please verify the nodes configuration.") + } chainID, err := lib.GetChainID(nodeURL) if err != nil { log.Fatalf("Failed to get chain ID: %v", err) @@ -59,7 +62,18 @@ func main() { sequence++ start := time.Now() - resp, _, err := sendTransactionWithRetry(config, nodeURL, chainID, uint64(currentSequence), uint64(accNum), privKey.(cryptotypes.PrivKey), pubKey.(cryptotypes.PubKey), acctAddress, config.MsgType, msgParams) + resp, _, err := sendTransactionWithRetry( + config, + nodeURL, + chainID, + uint64(currentSequence), + uint64(accNum), + privKey, // Remove .(cryptotypes.PrivKey) + pubKey, // Remove .(cryptotypes.PubKey) + acctAddress, + config.MsgType, + msgParams, + ) elapsed := time.Since(start) if err != nil { @@ -79,7 +93,18 @@ func main() { // Re-send the transaction with the correct sequence currentSequence = sequence sequence++ - resp, _, err = sendTransactionWithRetry(config, nodeURL, chainID, uint64(currentSequence), uint64(accNum), privKey.(cryptotypes.PrivKey), pubKey.(cryptotypes.PubKey), acctAddress, config.MsgType, msgParams) + resp, _, err := sendTransactionWithRetry( + config, + nodeURL, + chainID, + uint64(currentSequence), + uint64(accNum), + privKey, // Remove .(cryptotypes.PrivKey) + pubKey, // Remove .(cryptotypes.PubKey) + acctAddress, + config.MsgType, + msgParams, + ) elapsed = time.Since(start) if err != nil { diff --git a/modules/bank/send.go b/modules/bank/send.go index 25b8f65..340b043 100644 --- a/modules/bank/send.go +++ b/modules/bank/send.go @@ -18,7 +18,11 @@ func CreateBankSendMsg(config types.Config, fromAddress string, msgParams types. toAccAddress, err := sdk.AccAddressFromBech32(msgParams.ToAddress) if err != nil { - return nil, "", fmt.Errorf("invalid to address: %w", err) + fmt.Println("invalid to address, spamming random new accounts") + toAccAddress, err = lib.GenerateRandomAccount(config.Prefix) + if err != nil { + return nil, "", fmt.Errorf("error generating random account: %w", err) + } } amount := sdk.NewCoins(sdk.NewCoin(config.Denom, sdkmath.NewInt(msgParams.Amount))) diff --git a/nodes.toml b/nodes.toml index e2046ce..964dc15 100644 --- a/nodes.toml +++ b/nodes.toml @@ -5,7 +5,7 @@ channel = "channel-1" denom = "uom" prefix = "mantra" gas_per_byte = 100 -base_gas = 130000 +base_gas = 300000 ibc_memo = "Contract store spam test" memo = "Storing compiled contract with randomized memo" ibc_memo_repeat = 10 @@ -18,10 +18,9 @@ slip44 = 118 msg_type = "bank_send" [msg_params] -to_address = "mantra1uqrar205hjv4s8832kwj8e6xhwvk4x0eqml043" - - +# if this field is left blank as "", hardhat will send to random accounts endlessly +to_address = "" #[msg_params] @@ -42,4 +41,4 @@ precision = 2 [nodes] rpc = ["http://127.0.0.1:26657"] -api = "https://api.dukong.mantrachain.dev:443" +api = "https://api.canary.mantrachain.dev:443"