Skip to content

Commit

Permalink
add solana address from rand
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Dec 16, 2024
1 parent 7504de4 commit 9f249f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions testutil/sample/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package sample

import (
"crypto/ecdsa"
cryptoed25519 "crypto/ed25519"

"math/big"
"math/rand"
"strconv"
Expand Down Expand Up @@ -108,13 +110,31 @@ func SolanaPrivateKey(t *testing.T) solana.PrivateKey {
return privKey
}

func SolanaPrivateKeyFromRand(r *rand.Rand) (solana.PrivateKey, error) {
pub, priv, err := cryptoed25519.GenerateKey(r)
if err != nil {
return nil, err
}
var publicKey cryptoed25519.PublicKey
copy(publicKey[:], pub)
return solana.PrivateKey(priv), nil
}

// SolanaAddress returns a sample solana address
func SolanaAddress(t *testing.T) string {
privKey, err := solana.NewRandomPrivateKey()
require.NoError(t, err)
return privKey.PublicKey().String()
}

func SolanaAddressFromRand(r *rand.Rand) (string, error) {
privKey, err := SolanaPrivateKeyFromRand(r)
if err != nil {
return "", err
}
return privKey.PublicKey().String(), nil
}

// SolanaSignature returns a sample solana signature
func SolanaSignature(t *testing.T) solana.Signature {
// Generate a random keypair
Expand Down
11 changes: 11 additions & 0 deletions x/crosschain/keeper/msg_server_whitelist_erc20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (
)

func TestKeeper_WhitelistERC20(t *testing.T) {
r := sample.Rand()
firstTokenAddress, err := sample.SolanaAddressFromRand(r)
require.NoError(t, err)
secondTokenAddress, err := sample.SolanaAddressFromRand(r)
require.NoError(t, err)
tests := []struct {
name string
tokenAddress string
Expand All @@ -36,6 +41,12 @@ func TestKeeper_WhitelistERC20(t *testing.T) {
secondTokenAddress: sample.SolanaAddress(t),
chainID: getValidSolanaChainID(),
},
{
name: "can deploy and whitelist a spl",
tokenAddress: firstTokenAddress,
secondTokenAddress: secondTokenAddress,
chainID: getValidSolanaChainID(),
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 9f249f6

Please sign in to comment.