-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OTE-730] add test to check register affiliate auth (#2235)
Co-authored-by: Teddy Ding <[email protected]>
- Loading branch information
Showing
2 changed files
with
77 additions
and
1 deletion.
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
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 TestRegisterAffiliateInvalidSigner(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") | ||
} | ||
}) | ||
} | ||
} |
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