Skip to content

Commit cba4efe

Browse files
committed
feat: integrate definition contract calls for execution parameters
This commit enhances the GuardController and RuntimeRBAC implementations by replacing local execution parameter generation with calls to their respective deployed definition contracts. This change ensures a single source of truth for action specifications and improves the accuracy of execution parameters. Additionally, it removes outdated local helper functions and updates related documentation to reflect the new approach.
1 parent 9a7af59 commit cba4efe

26 files changed

Lines changed: 375 additions & 638 deletions

abi/GuardControllerDefinitions.abi.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@
6464
"stateMutability": "view",
6565
"type": "function"
6666
},
67+
{
68+
"inputs": [],
69+
"name": "EXECUTE_WITH_PAYMENT_SELECTOR",
70+
"outputs": [
71+
{
72+
"internalType": "bytes4",
73+
"name": "",
74+
"type": "bytes4"
75+
}
76+
],
77+
"stateMutability": "view",
78+
"type": "function"
79+
},
6780
{
6881
"inputs": [],
6982
"name": "EXECUTE_WITH_TIMELOCK_SELECTOR",

scripts/sanity-sdk/base/test-helpers.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ export async function getContractAddressFromArtifacts(
5454
}
5555
}
5656

57+
/**
58+
* Get definition library address.
59+
* Prefer deployed-addresses.json (development) so that after a Hardhat redeploy we use the new addresses.
60+
* Fall back to Truffle artifacts (e.g. after truffle migrate).
61+
* This avoids VM revert when artifacts point to an old/stale address on a redeployed chain.
62+
*/
63+
export async function getDefinitionAddress(contractName: string): Promise<Address> {
64+
const deployedPath = path.join(__dirname, '../../../deployed-addresses.json');
65+
if (fs.existsSync(deployedPath)) {
66+
const deployed = JSON.parse(fs.readFileSync(deployedPath, 'utf8'));
67+
const dev = deployed.development;
68+
if (dev && dev[contractName]?.address) {
69+
console.log(`📋 Using ${contractName} from deployed-addresses.json (development): ${dev[contractName].address}`);
70+
return dev[contractName].address as Address;
71+
}
72+
}
73+
74+
const fromArtifacts = await getContractAddressFromArtifacts(contractName);
75+
if (fromArtifacts) return fromArtifacts;
76+
77+
throw new Error(
78+
`Definition contract address not found for ${contractName}. ` +
79+
`Run deploy (truffle migrate or hardhat deploy-foundation-libraries) and ensure deployed-addresses.json or build/contracts has the address.`
80+
);
81+
}
82+
5783
/**
5884
* Advance blockchain time (for local Ganache)
5985
*/

scripts/sanity-sdk/guard-controller/base-test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import { Address, Hex } from 'viem';
77
import { GuardController } from '../../../sdk/typescript/contracts/core/GuardController.tsx';
88
import { BaseSDKTest, TestWallet } from '../base/BaseSDKTest.ts';
9-
import { getContractAddressFromArtifacts } from '../base/test-helpers.ts';
9+
import { getContractAddressFromArtifacts, getDefinitionAddress } from '../base/test-helpers.ts';
1010
import { getTestConfig } from '../base/test-config.ts';
1111
import { MetaTransactionSigner } from '../../../sdk/typescript/utils/metaTx/metaTransaction.tsx';
1212
import { MetaTransaction, MetaTxParams } from '../../../sdk/typescript/interfaces/lib.index.tsx';
1313
import { TxAction } from '../../../sdk/typescript/types/lib.index.tsx';
1414
import { GuardConfigActionType, GuardConfigAction } from '../../../sdk/typescript/types/core.execution.index.tsx';
15+
import { guardConfigBatchExecutionParams } from '../../../sdk/typescript/lib/definitions/GuardControllerDefinitions';
1516
import { keccak256, encodeAbiParameters, parseAbiParameters } from 'viem';
1617

1718
export interface GuardControllerRoles {
@@ -22,6 +23,8 @@ export interface GuardControllerRoles {
2223

2324
export abstract class BaseGuardControllerTest extends BaseSDKTest {
2425
protected guardController: GuardController | null = null;
26+
/** Deployed GuardControllerDefinitions library address (for execution params) */
27+
protected guardControllerDefinitionsAddress: Address | null = null;
2528
protected roles: GuardControllerRoles = {
2629
owner: '0x' as Address,
2730
broadcaster: '0x' as Address,
@@ -70,6 +73,8 @@ export abstract class BaseGuardControllerTest extends BaseSDKTest {
7073
throw new Error('Contract address not set');
7174
}
7275

76+
this.guardControllerDefinitionsAddress = await getDefinitionAddress('GuardControllerDefinitions');
77+
7378
// Create a wallet client for the owner (default)
7479
const walletClient = this.createWalletClient('wallet1');
7580

@@ -298,9 +303,12 @@ export abstract class BaseGuardControllerTest extends BaseSDKTest {
298303
},
299304
];
300305

301-
// Get execution params using the new batch method
306+
// Get execution params using the new batch method (via definition contract)
307+
if (!this.guardControllerDefinitionsAddress) {
308+
throw new Error('GuardControllerDefinitions address not set');
309+
}
302310
console.log(` 📋 Getting execution params for guard config batch...`);
303-
const executionParams = await this.guardController.guardConfigBatchExecutionParams(actions);
311+
const executionParams = await guardConfigBatchExecutionParams(this.publicClient, this.guardControllerDefinitionsAddress!, actions);
304312
console.log(` ✅ Execution params obtained`);
305313

306314
// Create meta-tx params
@@ -381,9 +389,12 @@ export abstract class BaseGuardControllerTest extends BaseSDKTest {
381389
},
382390
];
383391

384-
// Get execution params using the new batch method
392+
// Get execution params using the new batch method (via definition contract)
393+
if (!this.guardControllerDefinitionsAddress) {
394+
throw new Error('GuardControllerDefinitions address not set');
395+
}
385396
console.log(` 📋 Getting execution params for guard config batch (function registration)...`);
386-
const executionParams = await this.guardController.guardConfigBatchExecutionParams(actions);
397+
const executionParams = await guardConfigBatchExecutionParams(this.publicClient, this.guardControllerDefinitionsAddress!, actions);
387398
console.log(` ✅ Execution params obtained`);
388399

389400
// Create meta-tx params

scripts/sanity-sdk/run-all-tests.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ class SanitySDKTestRunner {
2525
'guard-controller': resolve(__dirname, 'guard-controller', 'run-tests.ts')
2626
};
2727

28-
private exampleTests: TestConfig = {
29-
'workflow': resolve(__dirname, 'workflow', 'run-tests.ts')
30-
};
28+
private exampleTests: TestConfig = {};
3129

3230
private results = {
3331
total: 0,
@@ -49,7 +47,6 @@ class SanitySDKTestRunner {
4947
console.log(' --secure-ownable Run secure-ownable tests only');
5048
console.log(' --runtime-rbac Run runtime-rbac tests only');
5149
console.log(' --guard-controller Run guard-controller tests only');
52-
console.log(' --workflow Run workflow tests only');
5350
console.log(' --help Show this help message');
5451
console.log();
5552
console.log('Examples:');

scripts/sanity-sdk/runtime-rbac/base-test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import { Address, Hex } from 'viem';
77
import { RuntimeRBAC } from '../../../sdk/typescript/contracts/core/RuntimeRBAC.tsx';
88
import { BaseSDKTest, TestWallet } from '../base/BaseSDKTest.ts';
9-
import { getContractAddressFromArtifacts } from '../base/test-helpers.ts';
9+
import { getContractAddressFromArtifacts, getDefinitionAddress } from '../base/test-helpers.ts';
1010
import { getTestConfig } from '../base/test-config.ts';
1111
import { MetaTransactionSigner } from '../../../sdk/typescript/utils/metaTx/metaTransaction.tsx';
1212
import { MetaTransaction, MetaTxParams, TxParams } from '../../../sdk/typescript/interfaces/lib.index.tsx';
1313
import { TxAction } from '../../../sdk/typescript/types/lib.index.tsx';
1414
import { keccak256, toBytes } from 'viem';
1515
import { encodeAbiParameters, parseAbiParameters } from 'viem';
16+
import { roleConfigBatchExecutionParams } from '../../../sdk/typescript/lib/definitions/RuntimeRBACDefinitions';
1617
import AccountBloxABIJson from '../../../sdk/typescript/abi/AccountBlox.abi.json';
1718

1819
export interface RuntimeRBACRoles {
@@ -54,6 +55,8 @@ export interface RoleConfigAction {
5455

5556
export abstract class BaseRuntimeRBACTest extends BaseSDKTest {
5657
protected runtimeRBAC: RuntimeRBAC | null = null;
58+
/** Deployed RuntimeRBACDefinitions library address (for execution params) */
59+
protected runtimeRBACDefinitionsAddress: Address | null = null;
5760
protected roles: RuntimeRBACRoles = {
5861
owner: '0x' as Address,
5962
broadcaster: '0x' as Address,
@@ -109,6 +112,8 @@ export abstract class BaseRuntimeRBACTest extends BaseSDKTest {
109112
throw new Error('Contract address not set');
110113
}
111114

115+
this.runtimeRBACDefinitionsAddress = await getDefinitionAddress('RuntimeRBACDefinitions');
116+
112117
// Create a wallet client for the owner (default)
113118
const walletClient = this.createWalletClient('wallet1');
114119

@@ -378,8 +383,11 @@ export abstract class BaseRuntimeRBACTest extends BaseSDKTest {
378383
throw new Error(`Wallet not found: ${signerWalletName}`);
379384
}
380385

381-
// Create execution params
382-
const executionParams = await this.runtimeRBAC.roleConfigBatchExecutionParams(actions);
386+
// Create execution params (via definition contract)
387+
if (!this.runtimeRBACDefinitionsAddress) {
388+
throw new Error('RuntimeRBACDefinitions address not set');
389+
}
390+
const executionParams = await roleConfigBatchExecutionParams(this.publicClient, this.runtimeRBACDefinitionsAddress, actions);
383391

384392
// Create meta-tx params
385393
const metaTxParams = await this.createMetaTxParams(

scripts/sanity-sdk/secure-ownable/base-test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Address, Hex } from 'viem';
77
import { SecureOwnable } from '../../../sdk/typescript/contracts/core/SecureOwnable.tsx';
88
import { BaseSDKTest, TestWallet } from '../base/BaseSDKTest.ts';
9-
import { getContractAddressFromArtifacts } from '../base/test-helpers.ts';
9+
import { getContractAddressFromArtifacts, getDefinitionAddress } from '../base/test-helpers.ts';
1010
import { getTestConfig } from '../base/test-config.ts';
1111
import { MetaTransactionSigner } from '../../../sdk/typescript/utils/metaTx/metaTransaction.tsx';
1212
import { MetaTransaction, MetaTxParams } from '../../../sdk/typescript/interfaces/lib.index.tsx';
@@ -21,6 +21,8 @@ export interface SecureOwnableRoles {
2121

2222
export abstract class BaseSecureOwnableTest extends BaseSDKTest {
2323
protected secureOwnable: SecureOwnable | null = null;
24+
/** Deployed SecureOwnableDefinitions library address (for execution params) */
25+
protected secureOwnableDefinitionsAddress: Address | null = null;
2426
protected roles: SecureOwnableRoles = {
2527
owner: '0x' as Address,
2628
broadcaster: '0x' as Address,
@@ -59,6 +61,8 @@ export abstract class BaseSecureOwnableTest extends BaseSDKTest {
5961
throw new Error('Contract address not set');
6062
}
6163

64+
this.secureOwnableDefinitionsAddress = await getDefinitionAddress('SecureOwnableDefinitions');
65+
6266
// Create a wallet client for the owner (default)
6367
const walletClient = this.createWalletClient('wallet1');
6468

scripts/sanity-sdk/secure-ownable/recovery-update-tests.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Address, Hex } from 'viem';
77
import { BaseSecureOwnableTest } from './base-test.ts';
88
import { TxAction } from '../../../sdk/typescript/types/lib.index.tsx';
99
import { FUNCTION_SELECTORS, OPERATION_TYPES } from '../../../sdk/typescript/types/core.access.index.tsx';
10+
import { updateRecoveryExecutionParams } from '../../../sdk/typescript/lib/definitions/SecureOwnableDefinitions';
1011

1112
export class RecoveryUpdateTests extends BaseSecureOwnableTest {
1213
constructor() {
@@ -86,10 +87,13 @@ export class RecoveryUpdateTests extends BaseSecureOwnableTest {
8687
(k) => this.wallets[k].address.toLowerCase() === ownerWallet.address.toLowerCase()
8788
) || 'wallet1';
8889

89-
// Get execution params for recovery update
90+
// Get execution params for recovery update (via definition contract)
91+
if (!this.secureOwnableDefinitionsAddress) {
92+
throw new Error('SecureOwnableDefinitions address not set');
93+
}
9094
let executionOptions: Hex;
9195
try {
92-
const result = await this.secureOwnable.updateRecoveryExecutionParams(newRecoveryAddress);
96+
const result = await updateRecoveryExecutionParams(this.publicClient, this.secureOwnableDefinitionsAddress, newRecoveryAddress);
9397
console.log(` 🔍 Raw execution params result:`, result, `(type: ${typeof result})`);
9498
executionOptions = result;
9599
this.assertTest(!!executionOptions && typeof executionOptions === 'string' && executionOptions.startsWith('0x'), 'Execution params created successfully');

scripts/sanity-sdk/secure-ownable/timelock-period-tests.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
* Tests updating the timelock period via meta-transaction
44
*/
55

6+
import { Hex } from 'viem';
67
import { BaseSecureOwnableTest } from './base-test.ts';
78
import { TxAction } from '../../../sdk/typescript/types/lib.index.tsx';
89
import { FUNCTION_SELECTORS, OPERATION_TYPES } from '../../../sdk/typescript/types/core.access.index.tsx';
10+
import { updateTimeLockExecutionParams } from '../../../sdk/typescript/lib/definitions/SecureOwnableDefinitions';
911

1012
export class TimelockPeriodTests extends BaseSecureOwnableTest {
1113
constructor() {
@@ -85,10 +87,13 @@ export class TimelockPeriodTests extends BaseSecureOwnableTest {
8587
(k) => this.wallets[k].address.toLowerCase() === ownerWallet.address.toLowerCase()
8688
) || 'wallet1';
8789

88-
// Get execution params for timelock update
90+
// Get execution params for timelock update (via definition contract)
91+
if (!this.secureOwnableDefinitionsAddress) {
92+
throw new Error('SecureOwnableDefinitions address not set');
93+
}
8994
let executionOptions: Hex;
9095
try {
91-
executionOptions = await this.secureOwnable.updateTimeLockExecutionParams(newTimelockSeconds);
96+
executionOptions = await updateTimeLockExecutionParams(this.publicClient, this.secureOwnableDefinitionsAddress, newTimelockSeconds);
9297
this.assertTest(!!executionOptions && typeof executionOptions === 'string' && executionOptions.startsWith('0x'), 'Execution params created successfully');
9398
console.log(` ✅ Execution params created for ${description}`);
9499
} catch (error: any) {

scripts/sanity-sdk/workflow/base-test.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)