Skip to content

Commit

Permalink
implement the random account bank send feature
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Oct 22, 2024
1 parent 36470b7 commit e2750a0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
15 changes: 15 additions & 0 deletions lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/BurntSushi/toml"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/somatic-labs/hardhat/types"
)

Expand Down Expand Up @@ -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
}
29 changes: 27 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion modules/bank/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
9 changes: 4 additions & 5 deletions nodes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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"

0 comments on commit e2750a0

Please sign in to comment.