Skip to content

Commit

Permalink
fix: fix plan set minter
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldonleedev committed Aug 15, 2024
1 parent 560055a commit 9fd0908
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
58 changes: 58 additions & 0 deletions x/plan/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,35 @@ func (suite *KeeperTestSuite) TestSetMinter() {
request.ContractAddress = yatAddr.Hex()
},
},
{
name: "fail - minter not is a contract",
request: &types.MsgSetMinter{
Sender: testAdmin.String(),
Minter: "0xB86aA614EDc512f4e3147779f964d420b43E44b4",
},
malleate: func(request *types.MsgSetMinter) {
suite.Commit()
// create agent
name := "sinohope4"
btcReceivingAddress := "3C7VPws9fMW3kcwRJvMkSVdqMs4SAhQCqq"
ethAddr := "0x6508d68f4e5931f93fadc3b7afac5092e195b80f"
description := "lorenzo"
url := "https://lorenzo-protocol.io"
agentId := suite.lorenzoApp.AgentKeeper.AddAgent(
suite.ctx,
name, btcReceivingAddress, ethAddr, description, url)
suite.Require().NotEqual(agentId, 0)
suite.Require().Equal(agentId, uint64(1))

// deploy yat contract
yatAddr, err := suite.lorenzoApp.PlanKeeper.DeployYATContract(
suite.ctx, "lorenzo", "ALRZ")
suite.Require().NoError(err)

request.ContractAddress = yatAddr.Hex()
},
expectErr: true,
},
{
name: "success - valid set minter",
request: &types.MsgSetMinter{
Expand Down Expand Up @@ -1085,6 +1114,35 @@ func (suite *KeeperTestSuite) TestRemoveMinter() {
request.ContractAddress = yatAddr.Hex()
},
},
{
name: "fail - minter not is a contract",
request: &types.MsgRemoveMinter{
Sender: testAdmin.String(),
Minter: "0xB86aA614EDc512f4e3147779f964d420b43E44b4",
},
malleate: func(request *types.MsgRemoveMinter) {
suite.Commit()
// create agent
name := "sinohope4"
btcReceivingAddress := "3C7VPws9fMW3kcwRJvMkSVdqMs4SAhQCqq"
ethAddr := "0x6508d68f4e5931f93fadc3b7afac5092e195b80f"
description := "lorenzo"
url := "https://lorenzo-protocol.io"
agentId := suite.lorenzoApp.AgentKeeper.AddAgent(
suite.ctx,
name, btcReceivingAddress, ethAddr, description, url)
suite.Require().NotEqual(agentId, 0)
suite.Require().Equal(agentId, uint64(1))

// deploy yat contract
yatAddr, err := suite.lorenzoApp.PlanKeeper.DeployYATContract(
suite.ctx, "lorenzo", "ALRZ")
suite.Require().NoError(err)

request.ContractAddress = yatAddr.Hex()
},
expectErr: true,
},
{
name: "success - valid remove minter",
request: &types.MsgRemoveMinter{
Expand Down
5 changes: 5 additions & 0 deletions x/plan/keeper/yat.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (k Keeper) UpdateMinter(
minter string,
updateType int,
) error {

// Check if the contract address is a valid address
if !common.IsHexAddress(contractAddress) {
return errorsmod.Wrap(types.ErrContractAddress, "invalid contract address")
Expand All @@ -50,6 +51,10 @@ func (k Keeper) UpdateMinter(
return types.ErrYatContractNotContract
}

planID := k.GetPlanIdByContractAddr(ctx, minter)
if planID == 0 {
return types.ErrStakePlanContractNotFound
}
// Check if the minter address is a valid address
if !common.IsHexAddress(minter) {
return errorsmod.Wrap(types.ErrEthAddress, "invalid Ethereum address")
Expand Down

0 comments on commit 9fd0908

Please sign in to comment.