Skip to content

Commit

Permalink
move to e2e folder
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 committed Sep 11, 2024
1 parent 95e5734 commit c8305cd
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 63 deletions.
73 changes: 73 additions & 0 deletions protocol/x/affiliates/e2e/register_affiliate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package affiliate_test

import (
"testing"

testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app"
constants "github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
"github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types"
"github.com/stretchr/testify/require"
)

func TestMsgServer_RegisterAffiliateInvalidSigner(t *testing.T) {
tApp := testapp.NewTestAppBuilder(t).Build()
ctx := tApp.InitChain()

testCases := []struct {
name string
referee string
affiliate string
signer string
expectSuccess bool
}{
{
name: "Valid signer (referee)",
referee: constants.BobAccAddress.String(),
affiliate: constants.AliceAccAddress.String(),
signer: constants.BobAccAddress.String(),
expectSuccess: true,
},
{
name: "Invalid signer (affiliate)",
referee: constants.BobAccAddress.String(),
affiliate: constants.AliceAccAddress.String(),
signer: constants.AliceAccAddress.String(),
expectSuccess: false,
},
{
name: "Invalid signer (non-related address)",
referee: constants.BobAccAddress.String(),
affiliate: constants.AliceAccAddress.String(),
signer: constants.CarlAccAddress.String(),
expectSuccess: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
msgRegisterAffiliate := types.MsgRegisterAffiliate{
Referee: tc.referee,
Affiliate: tc.affiliate,
}

checkTxMsgRegisterAffiliate := testapp.MustMakeCheckTx(
ctx,
tApp.App,
testapp.MustMakeCheckTxOptions{
AccAddressForSigning: tc.signer,
Gas: constants.TestGasLimit,
FeeAmt: constants.TestFeeCoins_5Cents,
},
&msgRegisterAffiliate,
)
checkTxResp := tApp.CheckTx(checkTxMsgRegisterAffiliate)

if tc.expectSuccess {
require.True(t, checkTxResp.IsOK(), "Expected CheckTx to succeed with valid signer")
} else {
require.True(t, checkTxResp.IsErr(), "Expected CheckTx to fail with invalid signer")
require.Contains(t, checkTxResp.Log, "pubKey does not match signer address")
}
})
}
}
63 changes: 0 additions & 63 deletions protocol/x/affiliates/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,66 +132,3 @@ func TestMsgServer_UpdateAffiliateTiers(t *testing.T) {
})
}
}

func TestMsgServer_RegisterAffiliateInvalidSigner(t *testing.T) {
tApp := testapp.NewTestAppBuilder(t).Build()
ctx := tApp.InitChain()

testCases := []struct {
name string
referee string
affiliate string
signer string
expectSuccess bool
}{
{
name: "Valid signer (referee)",
referee: constants.BobAccAddress.String(),
affiliate: constants.AliceAccAddress.String(),
signer: constants.BobAccAddress.String(),
expectSuccess: true,
},
{
name: "Invalid signer (affiliate)",
referee: constants.BobAccAddress.String(),
affiliate: constants.AliceAccAddress.String(),
signer: constants.AliceAccAddress.String(),
expectSuccess: false,
},
{
name: "Invalid signer (non-related address)",
referee: constants.BobAccAddress.String(),
affiliate: constants.AliceAccAddress.String(),
signer: constants.CarlAccAddress.String(),
expectSuccess: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
msgRegisterAffiliate := types.MsgRegisterAffiliate{
Referee: tc.referee,
Affiliate: tc.affiliate,
}

checkTxMsgRegisterAffiliate := testapp.MustMakeCheckTx(
ctx,
tApp.App,
testapp.MustMakeCheckTxOptions{
AccAddressForSigning: tc.signer,
Gas: constants.TestGasLimit,
FeeAmt: constants.TestFeeCoins_5Cents,
},
&msgRegisterAffiliate,
)
checkTxResp := tApp.CheckTx(checkTxMsgRegisterAffiliate)

if tc.expectSuccess {
require.True(t, checkTxResp.IsOK(), "Expected CheckTx to succeed with valid signer")
} else {
require.True(t, checkTxResp.IsErr(), "Expected CheckTx to fail with invalid signer")
require.Contains(t, checkTxResp.Log, "pubKey does not match signer address")
}
})
}
}

0 comments on commit c8305cd

Please sign in to comment.