From 5d95841b45fa91c91941eac04c0a8a400593fa3c Mon Sep 17 00:00:00 2001 From: freeelancer <lmengsplist96@gmail.com> Date: Tue, 12 Mar 2024 14:43:56 +0800 Subject: [PATCH] removed adding ctx setting --- .../src/modules/smartaccount/auth.test.ts | 8 +++----- .../src/modules/smartaccount/pretx.test.ts | 4 ++-- x/smartaccount/ante/auth.go | 3 --- x/smartaccount/ante/pretransaction.go | 15 ++++++++++++++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/integration-tests/src/modules/smartaccount/auth.test.ts b/integration-tests/src/modules/smartaccount/auth.test.ts index c4b15ba4..8685b0f8 100644 --- a/integration-tests/src/modules/smartaccount/auth.test.ts +++ b/integration-tests/src/modules/smartaccount/auth.test.ts @@ -1,5 +1,5 @@ -import { Coin, Coins, MsgDelegate, MsgInstantiateContract, MsgSend, MsgStoreCode, SimplePublicKey, ValAddress } from "@terra-money/feather.js"; -import { AuthorizationMsg, Initialization, MsgCreateSmartAccount, MsgUpdateAuthorization, MsgUpdateTransactionHooks } from "@terra-money/feather.js/dist/core/smartaccount"; +import { Coins, MsgInstantiateContract, MsgSend, MsgStoreCode, SimplePublicKey } from "@terra-money/feather.js"; +import { AuthorizationMsg, Initialization, MsgCreateSmartAccount, MsgUpdateAuthorization } from "@terra-money/feather.js/dist/core/smartaccount"; import fs from "fs"; import path from 'path'; import { blockInclusion, getLCDClient, getMnemonics } from "../../helpers"; @@ -15,10 +15,8 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/ const pubkey = accounts.mnemonic4.publicKey; expect(pubkey).toBeDefined(); - // TODO: convert pubkey to base64 string similar to golang pubkey.Bytes() const pubkeybb = pubkey as SimplePublicKey; const pubkeyStr = pubkeybb.key; - // AsCe1GUUuW2cT63a35JRpGYaJ6/xIZXvrZRfRGsyxIhK const initMsg = Initialization.fromData({ account: controlledAccountAddress, msg: pubkeyStr, @@ -27,7 +25,7 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/ const deployer = LCD.chain1.wallet(accounts.tokenFactoryMnemonic); const deployerAddress = accounts.tokenFactoryMnemonic.accAddress("terra"); - let authContractAddress: string, limitContractAddress: string; + let authContractAddress: string; test('Deploy smart account auth contract', async () => { try { diff --git a/integration-tests/src/modules/smartaccount/pretx.test.ts b/integration-tests/src/modules/smartaccount/pretx.test.ts index a34a4f6a..9587d6ff 100644 --- a/integration-tests/src/modules/smartaccount/pretx.test.ts +++ b/integration-tests/src/modules/smartaccount/pretx.test.ts @@ -113,7 +113,7 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/ } }); - test.only('Transaction should fail for limit', async () => { + test('Transaction should fail for limit', async () => { try { // signing with the controlledAccountAddress should now fail let tx = await wallet.createAndSignTx({ @@ -129,7 +129,7 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/ }); let result = await LCD.chain1.tx.broadcastSync(tx, "test-1"); console.log(result) - expect(result.raw_log).toEqual("Unauthorized message type"); + expect(result.raw_log).toEqual("Unauthorized: Unauthorized message type: execute wasm contract failed"); } catch (e:any) { console.log(e) expect(e).toBeUndefined(); diff --git a/x/smartaccount/ante/auth.go b/x/smartaccount/ante/auth.go index c7899b22..0f8a5121 100644 --- a/x/smartaccount/ante/auth.go +++ b/x/smartaccount/ante/auth.go @@ -93,9 +93,6 @@ func (sad SmartAccountAuthDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu return ctx, err } - // set the setting in the context for the pre and post tx handlers - ctx = ctx.WithValue(types.ModuleName, setting) - // run through the custom authorization verification if setting.Authorization != nil && len(setting.Authorization) > 0 { success, err := sad.CustomAuthVerify( diff --git a/x/smartaccount/ante/pretransaction.go b/x/smartaccount/ante/pretransaction.go index 2a021b4b..a874ee20 100644 --- a/x/smartaccount/ante/pretransaction.go +++ b/x/smartaccount/ante/pretransaction.go @@ -25,9 +25,22 @@ func NewPreTransactionHookDecorator(sak SmartAccountKeeper, wk WasmKeeper) PreTr } func (pth PreTransactionHookDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - setting, ok := ctx.Value(types.ModuleName).(types.Setting) + sigTx, ok := tx.(authsigning.SigVerifiableTx) if !ok { + return ctx, sdkerrors.ErrInvalidType.Wrap("expected SigVerifiableTx") + } + + // Signer here is the account that the state transition is affecting + // e.g. Account that is transferring some Coins + signers := sigTx.GetSigners() + account := signers[0] + accountStr := account.String() + + setting, err := pth.smartAccountKeeper.GetSetting(ctx, accountStr) + if sdkerrors.ErrKeyNotFound.Is(err) { return next(ctx, tx, simulate) + } else if err != nil { + return ctx, err } if setting.PreTransaction != nil && len(setting.PreTransaction) > 0 {