Skip to content

Commit

Permalink
change update auth message
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Mar 7, 2024
1 parent 519bdca commit 07092bc
Show file tree
Hide file tree
Showing 14 changed files with 504 additions and 75 deletions.
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ func NewTerraAppKeepers(
keepers.SmartAccountKeeper = smartaccountkeeper.NewKeeper(
appCodec,
keys[smartaccounttypes.StoreKey],
keepers.WasmKeeper.Keeper,
)

keepers.Ics20WasmHooks.ContractKeeper = keepers.WasmKeeper.Keeper
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/

// TODO: convert pubkey to base64 string similar to golang pubkey.Bytes()
const pubkeybb = pubkey as PublicKey

const ggg = pubkeybb.toAmino()

const key = ggg.value as string;
Expand All @@ -42,7 +43,7 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/
let tx = await deployer.createAndSignTx({
msgs: [new MsgStoreCode(
deployerAddress,
fs.readFileSync(path.join(__dirname, "/../../contracts/smart_auth_contract.wasm")).toString("base64"),
fs.readFileSync(path.join(__dirname, "/../../x/smartaccount/test_helpers/test_data/smart_auth_contract.wasm")).toString("base64"),
)],
chainID: "test-1",
});
Expand Down
3 changes: 2 additions & 1 deletion proto/terra/smartaccount/v1/setting.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package terra.smartaccount.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "terra/smartaccount/v1/wasm.proto";

option go_package = "github.com/terra-money/core/v2/x/smartaccount/types";

Expand All @@ -26,5 +27,5 @@ message Setting {

message AuthorizationMsg {
string contract_address = 1;
string init_msg = 2;
Initialization init_msg = 2;
}
15 changes: 15 additions & 0 deletions proto/terra/smartaccount/v1/wasm.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";
package terra.smartaccount.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/terra-money/core/v2/x/smartaccount/types";

message Initialization {
repeated string senders = 1 [(gogoproto.jsontag) = "senders"];
string account = 2 [(gogoproto.jsontag) = "account"];
bytes msg = 3 [(gogoproto.jsontag) = "msg"];
}



4 changes: 2 additions & 2 deletions x/smartaccount/ante/tests/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *AnteTestSuite) TestAuthAnteHandler() {

// create initMsg
initMsg := smartaccounttypes.Initialization{
Sender: acc.String(),
Senders: []string{},
Account: acc.String(),
Msg: pkEncoded,
}
Expand All @@ -69,7 +69,7 @@ func (s *AnteTestSuite) TestAuthAnteHandler() {
// set settings
authMsg := &smartaccounttypes.AuthorizationMsg{
ContractAddress: contractAddr.String(),
InitMsg: string(sudoInitMsgBs),
InitMsg: sudoInitMsg.Initialization,
}
err = s.SmartAccountKeeper.SetSetting(s.Ctx, smartaccounttypes.Setting{
Owner: acc.String(),
Expand Down
21 changes: 1 addition & 20 deletions x/smartaccount/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func (ms MsgServer) UpdateAuthorization(
) (*types.MsgUpdateAuthorizationResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Run through the authorization messages and check if they are valid
// Should be either done here or the auth ante handler
setting, err := ms.k.GetSetting(ctx, msg.Account)
if sdkerrors.ErrKeyNotFound.Is(err) {
setting = &types.Setting{
Expand All @@ -56,24 +54,7 @@ func (ms MsgServer) UpdateAuthorization(
setting.Authorization = msg.AuthorizationMsgs
// TODO: check if this is right
for _, auth := range msg.AuthorizationMsgs {
if auth.ContractAddress == "" {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("contract address cannot be empty")
}
if auth.InitMsg == "" {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("init msg cannot be empty")
}
var sudoMsg types.SudoMsg
err := json.Unmarshal([]byte(auth.InitMsg), &sudoMsg)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("failed to unmarshal auth msg: %s", err)
}

initMsg := types.Initialization{
Sender: sudoMsg.Authorization.Senders[0],
Account: sudoMsg.Authorization.Senders[0],
Msg: sudoMsg.Authorization.Data,
}
sudoInitMsg := types.SudoMsg{Initialization: &initMsg}
sudoInitMsg := types.SudoMsg{Initialization: auth.InitMsg}
sudoInitMsgBs, err := json.Marshal(sudoInitMsg)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions x/smartaccount/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *IntegrationTestSuite) TestMsgUpdateAuthorization() {
// update authorization
authorization := types.AuthorizationMsg{
ContractAddress: "abc",
InitMsg: "abc",
InitMsg: &types.Initialization{},
}
msgUpdate := types.NewMsgUpdateAuthorization(sender.String(), []*types.AuthorizationMsg{&authorization}, true)
_, err = ms.UpdateAuthorization(s.Ctx, msgUpdate)
Expand All @@ -66,7 +66,7 @@ func (s *IntegrationTestSuite) TestMsgUpdateAuthorization() {
// update authorization again
authorization2 := types.AuthorizationMsg{
ContractAddress: "bbc",
InitMsg: "bbc",
InitMsg: &types.Initialization{},
}
msgUpdate2 := types.NewMsgUpdateAuthorization(sender.String(), []*types.AuthorizationMsg{&authorization2}, true)
_, err = ms.UpdateAuthorization(s.Ctx, msgUpdate2)
Expand Down
Binary file modified x/smartaccount/test_helpers/test_data/smart_auth_contract.wasm
Binary file not shown.
3 changes: 0 additions & 3 deletions x/smartaccount/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

sdk "github.com/cosmos/cosmos-sdk/types"
acctypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
Expand All @@ -27,6 +25,5 @@ type BankKeeper interface {

// WasmKeeper defines the expected interface needed to retrieve cosmwasm contracts.
type WasmKeeper interface {
GetContractInfo(ctx sdk.Context, contractAddr sdk.AccAddress) (wasmtypes.ContractInfo, error)
Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error)
}
91 changes: 51 additions & 40 deletions x/smartaccount/types/setting.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions x/smartaccount/types/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ type SudoMsg struct {
PostTransaction *PostTransaction `json:"post_transaction,omitempty"`
}

type Initialization struct {
Sender string `json:"sender"`
Account string `json:"account"`
Msg []byte `json:"msg"`
}

type Authorization struct {
Senders []string `json:"senders"`
Account string `json:"account"`
Expand Down
Loading

0 comments on commit 07092bc

Please sign in to comment.