-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: extend solana unit tests (#3158)
* improve inbound tests * fix terminology * add outbound tests for withdraw spl * PR comments * PR comment
- Loading branch information
Showing
11 changed files
with
478 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,78 @@ | ||
package solana_test | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/gagliardetto/solana-go" | ||
"github.com/zeta-chain/node/pkg/chains" | ||
contracts "github.com/zeta-chain/node/pkg/contracts/solana" | ||
"github.com/zeta-chain/node/testutil" | ||
) | ||
|
||
func Test_MsgWithdrawHash(t *testing.T) { | ||
t.Run("should pass for archived inbound, receipt and cctx", func(t *testing.T) { | ||
t.Run("should calculate expected hash", func(t *testing.T) { | ||
// ARRANGE | ||
// #nosec G115 always positive | ||
chainID := uint64(chains.SolanaLocalnet.ChainId) | ||
nonce := uint64(0) | ||
amount := uint64(1336000) | ||
to := solana.MustPublicKeyFromBase58("37yGiHAnLvWZUNVwu9esp74YQFqxU1qHCbABkDvRddUQ") | ||
|
||
wantHash := "aa609ef9480303e8d743f6e36fe1bea0cc56b8d27dcbd8220846125c1181b681" | ||
wantHashBytes, err := hex.DecodeString(wantHash) | ||
require.NoError(t, err) | ||
wantHashBytes := testutil.HexToBytes(t, wantHash) | ||
|
||
// ACT | ||
// create new withdraw message | ||
hash := contracts.NewMsgWithdraw(chainID, nonce, amount, to).Hash() | ||
require.True(t, bytes.Equal(hash[:], wantHashBytes)) | ||
|
||
// ASSERT | ||
require.EqualValues(t, hash[:], wantHashBytes) | ||
}) | ||
} | ||
|
||
func Test_MsgWhitelistHash(t *testing.T) { | ||
t.Run("should pass for archived inbound, receipt and cctx", func(t *testing.T) { | ||
t.Run("should calculate expected hash", func(t *testing.T) { | ||
// ARRANGE | ||
// #nosec G115 always positive | ||
chainID := uint64(chains.SolanaLocalnet.ChainId) | ||
nonce := uint64(0) | ||
whitelistCandidate := solana.MustPublicKeyFromBase58("37yGiHAnLvWZUNVwu9esp74YQFqxU1qHCbABkDvRddUQ") | ||
whitelistEntry := solana.MustPublicKeyFromBase58("2kJndCL9NBR36ySiQ4bmArs4YgWQu67LmCDfLzk5Gb7s") | ||
|
||
wantHash := "cde8fa3ab24b50320db1c47f30492e789177d28e76208176f0a52b8ed54ce2dd" | ||
wantHashBytes, err := hex.DecodeString(wantHash) | ||
require.NoError(t, err) | ||
wantHashBytes := testutil.HexToBytes(t, wantHash) | ||
|
||
// ACT | ||
// create new withdraw message | ||
hash := contracts.NewMsgWhitelist(whitelistCandidate, whitelistEntry, chainID, nonce).Hash() | ||
require.True(t, bytes.Equal(hash[:], wantHashBytes)) | ||
|
||
// ASSERT | ||
require.EqualValues(t, hash[:], wantHashBytes) | ||
}) | ||
} | ||
|
||
func Test_MsgWithdrawSPLHash(t *testing.T) { | ||
t.Run("should calculate expected hash", func(t *testing.T) { | ||
// ARRANGE | ||
// #nosec G115 always positive | ||
chainID := uint64(chains.SolanaLocalnet.ChainId) | ||
nonce := uint64(0) | ||
amount := uint64(1336000) | ||
mintAccount := solana.MustPublicKeyFromBase58("AS48jKNQsDGkEdDvfwu1QpqjtqbCadrAq9nGXjFmdX3Z") | ||
to := solana.MustPublicKeyFromBase58("37yGiHAnLvWZUNVwu9esp74YQFqxU1qHCbABkDvRddUQ") | ||
toAta, _, err := solana.FindAssociatedTokenAddress(to, mintAccount) | ||
require.NoError(t, err) | ||
|
||
wantHash := "87fa5c0ed757c6e1ea9d8976537eaf7868bc1f1bbf55ab198a01645d664fe0ae" | ||
wantHashBytes := testutil.HexToBytes(t, wantHash) | ||
|
||
// ACT | ||
// create new withdraw message | ||
hash := contracts.NewMsgWithdrawSPL(chainID, nonce, amount, 8, mintAccount, to, toAta).Hash() | ||
|
||
// ASSERT | ||
require.EqualValues(t, hash[:], wantHashBytes) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.