Skip to content

Commit

Permalink
fix: thorchain claim server address
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyasbhat0 committed Oct 16, 2024
1 parent b9658d5 commit b014c2c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion x/claim/keeper/msg_server_claim_thorchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (k msgServer) ClaimThorchain(goCtx context.Context, msg *types.MsgClaimThor
k.Logger(ctx).Info(msg.Creator)

// only allow thorchain claim server address to call this function
if msg.Creator != "tarkeo1z02ke8639m47g9dfrheegr2u9zecegt5qvtj00" || msg.Creator == "arkeo1z02ke8639m47g9dfrheegr2u9zecegt50fjg7v" {
if msg.Creator != "tarkeo1z02ke8639m47g9dfrheegr2u9zecegt5qvtj00" && msg.Creator != "arkeo1z02ke8639m47g9dfrheegr2u9zecegt50fjg7v" {
return nil, errors.Wrapf(types.ErrInvalidCreator, "Invalid Creator %s", msg.Creator)
}

Expand Down
74 changes: 73 additions & 1 deletion x/claim/keeper/msg_server_claim_thorchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/arkeonetwork/arkeo/x/claim/types"
)

func TestClaimThorchain(t *testing.T) {
func TestClaimThorchainTestnetAddress(t *testing.T) {
msgServer, keepers, ctx := setupMsgServer(t)
sdkCtx := sdk.UnwrapSDKContext(ctx)

Expand Down Expand Up @@ -81,3 +81,75 @@ func TestClaimThorchain(t *testing.T) {
_, err = msgServer.ClaimThorchain(ctx, &claimMessage)
require.ErrorIs(t, err, types.ErrNoClaimableAmount)
}

func TestClaimThorchainMainnetAddress(t *testing.T) {
msgServer, keepers, ctx := setupMsgServer(t)
sdkCtx := sdk.UnwrapSDKContext(ctx)

config := sdk.GetConfig()
config.SetBech32PrefixForAccount("arkeo", "arkeopub")

arkeoServerAddress, err := sdk.AccAddressFromBech32("arkeo1z02ke8639m47g9dfrheegr2u9zecegt50fjg7v")
require.NoError(t, err)

fromAddr := utils.GetRandomArkeoAddress()
toAddr := utils.GetRandomArkeoAddress()

claimRecordFrom := types.ClaimRecord{
Chain: types.ARKEO,
Address: fromAddr.String(),
AmountClaim: sdk.NewInt64Coin(types.DefaultClaimDenom, 100),
AmountVote: sdk.NewInt64Coin(types.DefaultClaimDenom, 100),
AmountDelegate: sdk.NewInt64Coin(types.DefaultClaimDenom, 100),
}
claimRecordTo := types.ClaimRecord{
Chain: types.ARKEO,
Address: toAddr.String(),
AmountClaim: sdk.NewInt64Coin(types.DefaultClaimDenom, 100),
AmountVote: sdk.NewInt64Coin(types.DefaultClaimDenom, 100),
AmountDelegate: sdk.NewInt64Coin(types.DefaultClaimDenom, 100),
}
err = keepers.ClaimKeeper.SetClaimRecord(sdkCtx, claimRecordFrom)
require.NoError(t, err)
err = keepers.ClaimKeeper.SetClaimRecord(sdkCtx, claimRecordTo)
require.NoError(t, err)

// mint coins to module account
err = keepers.BankKeeper.MintCoins(sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(types.DefaultClaimDenom, 10000)))
require.NoError(t, err)

invalidClaimMessage := types.MsgClaimThorchain{
Creator: fromAddr.String(),
FromAddress: fromAddr.String(),
ToAddress: toAddr.String(),
}
_, err = msgServer.ClaimThorchain(ctx, &invalidClaimMessage)
require.ErrorIs(t, types.ErrInvalidCreator, err)

claimMessage := types.MsgClaimThorchain{
Creator: arkeoServerAddress.String(),
FromAddress: fromAddr.String(),
ToAddress: toAddr.String(),
}
_, err = msgServer.ClaimThorchain(ctx, &claimMessage)
require.NoError(t, err)

// check if claimrecord is updated
claimRecordFrom, err = keepers.ClaimKeeper.GetClaimRecord(sdkCtx, fromAddr.String(), types.ARKEO)
require.NoError(t, err)
require.True(t, claimRecordFrom.IsEmpty())

claimRecordTo, err = keepers.ClaimKeeper.GetClaimRecord(sdkCtx, toAddr.String(), types.ARKEO)
require.NoError(t, err)
require.True(t, !claimRecordTo.IsEmpty())

require.Equal(t, claimRecordTo.Address, toAddr.String())
require.Equal(t, claimRecordTo.Chain, types.ARKEO)
require.Equal(t, claimRecordTo.AmountClaim, sdk.NewInt64Coin(types.DefaultClaimDenom, 200))
require.Equal(t, claimRecordTo.AmountVote, sdk.NewInt64Coin(types.DefaultClaimDenom, 200))
require.Equal(t, claimRecordTo.AmountDelegate, sdk.NewInt64Coin(types.DefaultClaimDenom, 200))

// attempt to claim again to ensure it fails.
_, err = msgServer.ClaimThorchain(ctx, &claimMessage)
require.ErrorIs(t, err, types.ErrNoClaimableAmount)
}

0 comments on commit b014c2c

Please sign in to comment.