Skip to content

Commit

Permalink
removed adding ctx setting
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Mar 12, 2024
1 parent d89467f commit 5d95841
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
8 changes: 3 additions & 5 deletions integration-tests/src/modules/smartaccount/auth.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/modules/smartaccount/pretx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions x/smartaccount/ante/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 14 additions & 1 deletion x/smartaccount/ante/pretransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5d95841

Please sign in to comment.