@5ive-tech/sdk 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +279 -0
- package/dist/FiveSDK.d.ts +336 -0
- package/dist/FiveSDK.js +395 -0
- package/dist/accounts/index.d.ts +254 -0
- package/dist/accounts/index.js +543 -0
- package/dist/assets/vm/dummy.file +0 -0
- package/dist/assets/vm/five_vm_wasm.d.ts +762 -0
- package/dist/assets/vm/five_vm_wasm.js +3754 -0
- package/dist/assets/vm/five_vm_wasm_bg.js +3307 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm +0 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm.d.ts +247 -0
- package/dist/assets/vm/package.json +11 -0
- package/dist/bin/gen-types.d.ts +2 -0
- package/dist/bin/gen-types.js +35 -0
- package/dist/compiler/BytecodeCompiler.d.ts +83 -0
- package/dist/compiler/BytecodeCompiler.js +379 -0
- package/dist/config/ConfigManager.d.ts +13 -0
- package/dist/config/ConfigManager.js +27 -0
- package/dist/config/ProgramIdResolver.d.ts +62 -0
- package/dist/config/ProgramIdResolver.js +104 -0
- package/dist/crypto/index.d.ts +211 -0
- package/dist/crypto/index.js +451 -0
- package/dist/encoding/ParameterEncoder.d.ts +31 -0
- package/dist/encoding/ParameterEncoder.js +278 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +28 -0
- package/dist/lib/bytecode-encoder.d.ts +62 -0
- package/dist/lib/bytecode-encoder.js +281 -0
- package/dist/logging/index.d.ts +9 -0
- package/dist/logging/index.js +10 -0
- package/dist/metadata/index.d.ts +213 -0
- package/dist/metadata/index.js +296 -0
- package/dist/modules/accounts.d.ts +60 -0
- package/dist/modules/accounts.js +275 -0
- package/dist/modules/deploy.d.ts +90 -0
- package/dist/modules/deploy.js +1118 -0
- package/dist/modules/execute.d.ts +90 -0
- package/dist/modules/execute.js +649 -0
- package/dist/modules/fees.d.ts +14 -0
- package/dist/modules/fees.js +112 -0
- package/dist/modules/namespaces.d.ts +39 -0
- package/dist/modules/namespaces.js +190 -0
- package/dist/modules/state-diff.d.ts +35 -0
- package/dist/modules/state-diff.js +342 -0
- package/dist/modules/vm-state.d.ts +7 -0
- package/dist/modules/vm-state.js +44 -0
- package/dist/program/AccountResolver.d.ts +67 -0
- package/dist/program/AccountResolver.js +134 -0
- package/dist/program/BorshSchemaGenerator.d.ts +8 -0
- package/dist/program/BorshSchemaGenerator.js +57 -0
- package/dist/program/FiveProgram.d.ts +144 -0
- package/dist/program/FiveProgram.js +282 -0
- package/dist/program/FunctionBuilder.d.ts +114 -0
- package/dist/program/FunctionBuilder.js +347 -0
- package/dist/program/ProgramAccount.d.ts +38 -0
- package/dist/program/ProgramAccount.js +170 -0
- package/dist/program/TypeGenerator.d.ts +90 -0
- package/dist/program/TypeGenerator.js +195 -0
- package/dist/program/index.d.ts +24 -0
- package/dist/program/index.js +21 -0
- package/dist/project/config.d.ts +5 -0
- package/dist/project/config.js +33 -0
- package/dist/project/toml.d.ts +6 -0
- package/dist/project/toml.js +43 -0
- package/dist/project/workspace.d.ts +160 -0
- package/dist/project/workspace.js +73 -0
- package/dist/testing/AccountMetaGenerator.d.ts +121 -0
- package/dist/testing/AccountMetaGenerator.js +261 -0
- package/dist/testing/AccountTestFixture.d.ts +211 -0
- package/dist/testing/AccountTestFixture.js +530 -0
- package/dist/testing/OnChainAccountManager.d.ts +81 -0
- package/dist/testing/OnChainAccountManager.js +260 -0
- package/dist/testing/StateSerializer.d.ts +65 -0
- package/dist/testing/StateSerializer.js +330 -0
- package/dist/testing/TestDiscovery.d.ts +79 -0
- package/dist/testing/TestDiscovery.js +274 -0
- package/dist/testing/TestRunner.d.ts +117 -0
- package/dist/testing/TestRunner.js +346 -0
- package/dist/testing/index.d.ts +14 -0
- package/dist/testing/index.js +13 -0
- package/dist/types.d.ts +356 -0
- package/dist/types.js +32 -0
- package/dist/utils/abi.d.ts +31 -0
- package/dist/utils/abi.js +92 -0
- package/dist/utils/transaction.d.ts +5 -0
- package/dist/utils/transaction.js +48 -0
- package/dist/validation/InputValidator.d.ts +142 -0
- package/dist/validation/InputValidator.js +332 -0
- package/dist/validation/index.d.ts +4 -0
- package/dist/validation/index.js +4 -0
- package/dist/wasm/compiler/AbiLogic.d.ts +4 -0
- package/dist/wasm/compiler/AbiLogic.js +37 -0
- package/dist/wasm/compiler/AnalysisLogic.d.ts +6 -0
- package/dist/wasm/compiler/AnalysisLogic.js +61 -0
- package/dist/wasm/compiler/CompilationLogic.d.ts +10 -0
- package/dist/wasm/compiler/CompilationLogic.js +431 -0
- package/dist/wasm/compiler/FiveCompiler.d.ts +48 -0
- package/dist/wasm/compiler/FiveCompiler.js +183 -0
- package/dist/wasm/compiler/InfoLogic.d.ts +6 -0
- package/dist/wasm/compiler/InfoLogic.js +24 -0
- package/dist/wasm/compiler/OptimizationLogic.d.ts +2 -0
- package/dist/wasm/compiler/OptimizationLogic.js +13 -0
- package/dist/wasm/compiler/ValidationLogic.d.ts +7 -0
- package/dist/wasm/compiler/ValidationLogic.js +26 -0
- package/dist/wasm/compiler/index.d.ts +2 -0
- package/dist/wasm/compiler/index.js +2 -0
- package/dist/wasm/compiler/types.d.ts +8 -0
- package/dist/wasm/compiler/types.js +1 -0
- package/dist/wasm/compiler/utils.d.ts +8 -0
- package/dist/wasm/compiler/utils.js +75 -0
- package/dist/wasm/index.d.ts +9 -0
- package/dist/wasm/index.js +12 -0
- package/dist/wasm/instance.d.ts +1 -0
- package/dist/wasm/instance.js +26 -0
- package/dist/wasm/loader.d.ts +7 -0
- package/dist/wasm/loader.js +112 -0
- package/dist/wasm/vm.d.ts +33 -0
- package/dist/wasm/vm.js +250 -0
- package/package.json +59 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Meta Generator for Five VM Testing
|
|
3
|
+
*
|
|
4
|
+
* Generates AccountMeta structures for testing account system scripts
|
|
5
|
+
* based on ABI requirements and constraint types (@signer, @mut, @init)
|
|
6
|
+
*/
|
|
7
|
+
import { SolanaPublicKeyUtils, Base58Utils } from '../crypto/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Account Meta Generator for Five VM test scripts
|
|
10
|
+
*/
|
|
11
|
+
export class AccountMetaGenerator {
|
|
12
|
+
/**
|
|
13
|
+
* Generate AccountMeta array from ABI function definition
|
|
14
|
+
*/
|
|
15
|
+
static async generateAccountsForFunction(abi, functionName, options = {}) {
|
|
16
|
+
const func = abi.functions?.[functionName];
|
|
17
|
+
if (!func) {
|
|
18
|
+
throw new Error(`Function '${functionName}' not found in ABI`);
|
|
19
|
+
}
|
|
20
|
+
const accountSpecs = func.accounts || [];
|
|
21
|
+
const accounts = [];
|
|
22
|
+
const stateData = new Map();
|
|
23
|
+
if (options.debug) {
|
|
24
|
+
console.log(`[AccountMetaGenerator] Generating accounts for ${functionName}:`);
|
|
25
|
+
console.log(` - Found ${accountSpecs.length} account requirements`);
|
|
26
|
+
}
|
|
27
|
+
for (const accountSpec of accountSpecs) {
|
|
28
|
+
const accountMeta = await this.generateAccountMeta(accountSpec, options);
|
|
29
|
+
accounts.push(accountMeta);
|
|
30
|
+
// Generate state data for state accounts
|
|
31
|
+
if (options.generateStateData && this.isStateAccount(accountSpec)) {
|
|
32
|
+
const state = this.generateStateData(accountSpec);
|
|
33
|
+
stateData.set(accountSpec.name, state);
|
|
34
|
+
}
|
|
35
|
+
if (options.debug) {
|
|
36
|
+
console.log(` - ${accountSpec.name}: ${accountMeta.pubkey} (signer: ${accountMeta.isSigner}, writable: ${accountMeta.isWritable})`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
script: functionName,
|
|
41
|
+
functionIndex: func.index,
|
|
42
|
+
accounts,
|
|
43
|
+
stateData: stateData.size > 0 ? stateData : undefined
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generate single AccountMeta from account specification
|
|
48
|
+
*/
|
|
49
|
+
static async generateAccountMeta(accountSpec, options) {
|
|
50
|
+
// Check cache for reusable accounts
|
|
51
|
+
const cacheKey = `${accountSpec.name}_${accountSpec.signer}_${accountSpec.writable}`;
|
|
52
|
+
if (options.reuseAccounts && this.accountCache.has(cacheKey)) {
|
|
53
|
+
const cached = this.accountCache.get(cacheKey);
|
|
54
|
+
if (options.debug) {
|
|
55
|
+
console.log(` [Cache Hit] Reusing account for ${accountSpec.name}: ${cached.pubkey}`);
|
|
56
|
+
}
|
|
57
|
+
return cached;
|
|
58
|
+
}
|
|
59
|
+
let accountMeta;
|
|
60
|
+
if (accountSpec.signer) {
|
|
61
|
+
// Generate new keypair for signer accounts
|
|
62
|
+
accountMeta = await this.generateSignerAccount(accountSpec, options);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Generate regular account for non-signer accounts
|
|
66
|
+
accountMeta = await this.generateRegularAccount(accountSpec, options);
|
|
67
|
+
}
|
|
68
|
+
// Cache for reuse
|
|
69
|
+
if (options.reuseAccounts) {
|
|
70
|
+
this.accountCache.set(cacheKey, accountMeta);
|
|
71
|
+
}
|
|
72
|
+
return accountMeta;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Generate signer account with keypair
|
|
76
|
+
*/
|
|
77
|
+
static async generateSignerAccount(accountSpec, options) {
|
|
78
|
+
// Generate new keypair for signer
|
|
79
|
+
const crypto = await import('crypto');
|
|
80
|
+
const keypair = crypto.generateKeyPairSync('ed25519', {
|
|
81
|
+
publicKeyEncoding: { type: 'spki', format: 'der' },
|
|
82
|
+
privateKeyEncoding: { type: 'pkcs8', format: 'der' }
|
|
83
|
+
});
|
|
84
|
+
// Extract raw public key (32 bytes) from SPKI DER encoding
|
|
85
|
+
// SPKI format for ed25519: 12-byte header + 32-byte key
|
|
86
|
+
const publicKeyDer = keypair.publicKey;
|
|
87
|
+
const publicKeyRaw = publicKeyDer.slice(-32); // Last 32 bytes are the raw key
|
|
88
|
+
const publicKey = Base58Utils.encode(new Uint8Array(publicKeyRaw));
|
|
89
|
+
// Extract private key (64 bytes from PKCS8: 32-byte seed + 32-byte public key)
|
|
90
|
+
const privateKeyDer = keypair.privateKey;
|
|
91
|
+
const secretKey = new Uint8Array(privateKeyDer.slice(-64, -32)); // Extract the seed
|
|
92
|
+
if (options.debug) {
|
|
93
|
+
console.log(` [Signer] Generated keypair for ${accountSpec.name}: ${publicKey}`);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
pubkey: publicKey,
|
|
97
|
+
isSigner: true,
|
|
98
|
+
isWritable: accountSpec.writable,
|
|
99
|
+
keypair: {
|
|
100
|
+
publicKey,
|
|
101
|
+
secretKey
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Generate regular (non-signer) account
|
|
107
|
+
*/
|
|
108
|
+
static async generateRegularAccount(accountSpec, options) {
|
|
109
|
+
// Generate random address for non-signer accounts
|
|
110
|
+
const randomAddress = SolanaPublicKeyUtils.random();
|
|
111
|
+
if (options.debug) {
|
|
112
|
+
console.log(` [Regular] Generated address for ${accountSpec.name}: ${randomAddress}`);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
pubkey: randomAddress,
|
|
116
|
+
isSigner: false,
|
|
117
|
+
isWritable: accountSpec.writable
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Check if account is a state account that needs data
|
|
122
|
+
*/
|
|
123
|
+
static isStateAccount(accountSpec) {
|
|
124
|
+
// Common patterns for state accounts
|
|
125
|
+
const statePatterns = [
|
|
126
|
+
'state',
|
|
127
|
+
'account',
|
|
128
|
+
'data',
|
|
129
|
+
'storage'
|
|
130
|
+
];
|
|
131
|
+
const name = accountSpec.name.toLowerCase();
|
|
132
|
+
return statePatterns.some(pattern => name.includes(pattern));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Generate mock state data for state accounts
|
|
136
|
+
*/
|
|
137
|
+
static generateStateData(accountSpec) {
|
|
138
|
+
// Generate appropriate state data based on account name
|
|
139
|
+
const name = accountSpec.name.toLowerCase();
|
|
140
|
+
if (name.includes('state')) {
|
|
141
|
+
return {
|
|
142
|
+
count: 42,
|
|
143
|
+
total_operations: 0,
|
|
144
|
+
admin: SolanaPublicKeyUtils.random(),
|
|
145
|
+
created_accounts: 0,
|
|
146
|
+
modification_count: 0
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (name.includes('init')) {
|
|
150
|
+
return {
|
|
151
|
+
created_accounts: 0,
|
|
152
|
+
admin: SolanaPublicKeyUtils.random()
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (name.includes('mut')) {
|
|
156
|
+
return {
|
|
157
|
+
modification_count: 0
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// Default state data
|
|
161
|
+
return {
|
|
162
|
+
value: 42,
|
|
163
|
+
owner: SolanaPublicKeyUtils.random()
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Format accounts for Five CLI execution
|
|
168
|
+
*/
|
|
169
|
+
static formatAccountsForCLI(context) {
|
|
170
|
+
const accounts = context.accounts.map(acc => acc.pubkey).join(',');
|
|
171
|
+
const keypairs = context.accounts
|
|
172
|
+
.filter(acc => acc.keypair)
|
|
173
|
+
.map(acc => ({
|
|
174
|
+
name: acc.pubkey,
|
|
175
|
+
keypair: acc.keypair
|
|
176
|
+
}));
|
|
177
|
+
return {
|
|
178
|
+
accountsParam: accounts,
|
|
179
|
+
keypairsNeeded: keypairs
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Generate accounts from .five file
|
|
184
|
+
*/
|
|
185
|
+
static async generateFromFiveFile(fiveFilePath, functionName = 'test', options = {}) {
|
|
186
|
+
const fs = await import('fs');
|
|
187
|
+
const path = await import('path');
|
|
188
|
+
if (!fs.existsSync(fiveFilePath)) {
|
|
189
|
+
throw new Error(`Five file not found: ${fiveFilePath}`);
|
|
190
|
+
}
|
|
191
|
+
const fiveData = JSON.parse(fs.readFileSync(fiveFilePath, 'utf8'));
|
|
192
|
+
const abi = fiveData.abi;
|
|
193
|
+
if (!abi || !abi.functions) {
|
|
194
|
+
throw new Error(`Invalid Five file: missing ABI or functions in ${fiveFilePath}`);
|
|
195
|
+
}
|
|
196
|
+
return this.generateAccountsForFunction(abi, functionName, options);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Clear account cache (useful for testing)
|
|
200
|
+
*/
|
|
201
|
+
static clearCache() {
|
|
202
|
+
this.accountCache.clear();
|
|
203
|
+
this.stateDataCache.clear();
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get account cache statistics
|
|
207
|
+
*/
|
|
208
|
+
static getCacheStats() {
|
|
209
|
+
return {
|
|
210
|
+
accountsCached: this.accountCache.size,
|
|
211
|
+
stateDataCached: this.stateDataCache.size
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
AccountMetaGenerator.accountCache = new Map();
|
|
216
|
+
AccountMetaGenerator.stateDataCache = new Map();
|
|
217
|
+
/**
|
|
218
|
+
* Utility functions for account management
|
|
219
|
+
*/
|
|
220
|
+
export class AccountTestUtils {
|
|
221
|
+
/**
|
|
222
|
+
* Create test accounts for common constraint patterns
|
|
223
|
+
*/
|
|
224
|
+
static async createStandardTestAccounts() {
|
|
225
|
+
const generator = AccountMetaGenerator;
|
|
226
|
+
const [payer, authority, state, readonly] = await Promise.all([
|
|
227
|
+
generator['generateSignerAccount']({ name: 'payer', signer: true, writable: true }, {}),
|
|
228
|
+
generator['generateSignerAccount']({ name: 'authority', signer: true, writable: false }, {}),
|
|
229
|
+
generator['generateRegularAccount']({ name: 'state', signer: false, writable: true }, {}),
|
|
230
|
+
generator['generateRegularAccount']({ name: 'readonly', signer: false, writable: false }, {})
|
|
231
|
+
]);
|
|
232
|
+
return { payer, authority, state, readonly };
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Validate account constraints match requirements
|
|
236
|
+
*/
|
|
237
|
+
static validateAccountConstraints(accounts, requirements) {
|
|
238
|
+
const errors = [];
|
|
239
|
+
if (accounts.length !== requirements.length) {
|
|
240
|
+
errors.push(`Account count mismatch: expected ${requirements.length}, got ${accounts.length}`);
|
|
241
|
+
return { valid: false, errors };
|
|
242
|
+
}
|
|
243
|
+
for (let i = 0; i < requirements.length; i++) {
|
|
244
|
+
const account = accounts[i];
|
|
245
|
+
const requirement = requirements[i];
|
|
246
|
+
if (account.isSigner !== requirement.signer) {
|
|
247
|
+
errors.push(`Account ${i} (${requirement.name}): signer mismatch - expected ${requirement.signer}, got ${account.isSigner}`);
|
|
248
|
+
}
|
|
249
|
+
if (account.isWritable !== requirement.writable) {
|
|
250
|
+
errors.push(`Account ${i} (${requirement.name}): writable mismatch - expected ${requirement.writable}, got ${account.isWritable}`);
|
|
251
|
+
}
|
|
252
|
+
if (requirement.signer && !account.keypair) {
|
|
253
|
+
errors.push(`Account ${i} (${requirement.name}): signer account missing keypair`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
valid: errors.length === 0,
|
|
258
|
+
errors
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Test Fixture Framework for Five VM
|
|
3
|
+
*
|
|
4
|
+
* Provides a reusable, composable pattern for testing Five account-system scripts.
|
|
5
|
+
* Builders use this to:
|
|
6
|
+
* 1. Define test accounts with specific constraints
|
|
7
|
+
* 2. Initialize account state before test execution
|
|
8
|
+
* 3. Validate constraints locally before on-chain testing
|
|
9
|
+
* 4. Reuse common account setups across multiple tests
|
|
10
|
+
*
|
|
11
|
+
* Example:
|
|
12
|
+
* ```
|
|
13
|
+
* const fixture = new AccountTestFixture()
|
|
14
|
+
* .addSignerAccount('payer')
|
|
15
|
+
* .addStateAccount('counter', { value: 0 })
|
|
16
|
+
* .addMutableAccount('target')
|
|
17
|
+
* .build();
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import { GeneratedAccountMeta } from './AccountMetaGenerator.js';
|
|
21
|
+
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
22
|
+
/**
|
|
23
|
+
* Account state initialization template
|
|
24
|
+
* Builders provide this to set initial account data
|
|
25
|
+
*/
|
|
26
|
+
export interface AccountStateTemplate {
|
|
27
|
+
[fieldName: string]: any;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Account specification for fixture building
|
|
31
|
+
* Describes what kind of account is needed
|
|
32
|
+
*/
|
|
33
|
+
export interface FixtureAccountSpec {
|
|
34
|
+
name: string;
|
|
35
|
+
type: 'signer' | 'mutable' | 'readonly' | 'state' | 'init';
|
|
36
|
+
state?: AccountStateTemplate;
|
|
37
|
+
description?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build options for fixture compilation
|
|
41
|
+
*/
|
|
42
|
+
export interface BuildOptions {
|
|
43
|
+
debug?: boolean;
|
|
44
|
+
mode?: 'local' | 'onchain';
|
|
45
|
+
connection?: Connection;
|
|
46
|
+
payer?: Keypair;
|
|
47
|
+
cleanup?: boolean;
|
|
48
|
+
fiveVMProgramId?: PublicKey;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Compiled fixture ready for test execution
|
|
52
|
+
* Contains all accounts and their metadata
|
|
53
|
+
*/
|
|
54
|
+
export interface CompiledFixture {
|
|
55
|
+
accounts: GeneratedAccountMeta[];
|
|
56
|
+
accountsByName: Map<string, GeneratedAccountMeta>;
|
|
57
|
+
stateData: Map<string, AccountStateTemplate>;
|
|
58
|
+
specs: FixtureAccountSpec[];
|
|
59
|
+
metadata: {
|
|
60
|
+
signerCount: number;
|
|
61
|
+
mutableCount: number;
|
|
62
|
+
readonlyCount: number;
|
|
63
|
+
stateCount: number;
|
|
64
|
+
};
|
|
65
|
+
cleanup?: () => Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Validation result from constraint checking
|
|
69
|
+
*/
|
|
70
|
+
export interface ConstraintValidationResult {
|
|
71
|
+
valid: boolean;
|
|
72
|
+
errors: string[];
|
|
73
|
+
warnings: string[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Test execution context with bound accounts
|
|
77
|
+
*/
|
|
78
|
+
export interface AccountExecutionContext {
|
|
79
|
+
fixture: CompiledFixture;
|
|
80
|
+
functionName: string;
|
|
81
|
+
parameters: any[];
|
|
82
|
+
accountAddresses: string[];
|
|
83
|
+
keypairs: Map<string, Uint8Array>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Account Test Fixture Builder
|
|
87
|
+
* Fluent API for constructing test account setups
|
|
88
|
+
*/
|
|
89
|
+
export declare class AccountTestFixture {
|
|
90
|
+
private specs;
|
|
91
|
+
private stateTemplates;
|
|
92
|
+
/**
|
|
93
|
+
* Add a signer account (@signer constraint)
|
|
94
|
+
* Used for transaction signers, authority checks
|
|
95
|
+
*/
|
|
96
|
+
addSignerAccount(name: string, options?: {
|
|
97
|
+
description?: string;
|
|
98
|
+
}): this;
|
|
99
|
+
/**
|
|
100
|
+
* Add a mutable account (@mut constraint)
|
|
101
|
+
* Can be modified by the script
|
|
102
|
+
*/
|
|
103
|
+
addMutableAccount(name: string, state?: AccountStateTemplate, options?: {
|
|
104
|
+
description?: string;
|
|
105
|
+
}): this;
|
|
106
|
+
/**
|
|
107
|
+
* Add a read-only account
|
|
108
|
+
* Cannot be modified by the script
|
|
109
|
+
*/
|
|
110
|
+
addReadOnlyAccount(name: string, state?: AccountStateTemplate, options?: {
|
|
111
|
+
description?: string;
|
|
112
|
+
}): this;
|
|
113
|
+
/**
|
|
114
|
+
* Add a state account (@mut state: StateType)
|
|
115
|
+
* Typically for program state storage
|
|
116
|
+
*/
|
|
117
|
+
addStateAccount(name: string, state?: AccountStateTemplate, options?: {
|
|
118
|
+
description?: string;
|
|
119
|
+
}): this;
|
|
120
|
+
/**
|
|
121
|
+
* Add an initialization account (@init constraint)
|
|
122
|
+
* For account creation patterns
|
|
123
|
+
*/
|
|
124
|
+
addInitAccount(name: string, options?: {
|
|
125
|
+
description?: string;
|
|
126
|
+
}): this;
|
|
127
|
+
/**
|
|
128
|
+
* Add multiple accounts in one call
|
|
129
|
+
* Useful for standard patterns
|
|
130
|
+
*/
|
|
131
|
+
addPattern(pattern: 'authorization' | 'state-mutation' | 'batch-operation'): this;
|
|
132
|
+
/**
|
|
133
|
+
* Compile fixture into accounts ready for execution
|
|
134
|
+
* Supports both local (synthetic) and on-chain (real) account modes
|
|
135
|
+
*/
|
|
136
|
+
build(options?: BuildOptions): Promise<CompiledFixture>;
|
|
137
|
+
/**
|
|
138
|
+
* Build fixture with local synthetic accounts (existing behavior)
|
|
139
|
+
*/
|
|
140
|
+
private buildLocal;
|
|
141
|
+
/**
|
|
142
|
+
* Build fixture with real on-chain accounts
|
|
143
|
+
*/
|
|
144
|
+
private buildOnChain;
|
|
145
|
+
/**
|
|
146
|
+
* Create individual account based on spec
|
|
147
|
+
*/
|
|
148
|
+
private createAccount;
|
|
149
|
+
/**
|
|
150
|
+
* Validate fixture against ABI constraints
|
|
151
|
+
*/
|
|
152
|
+
validateAgainstABI(abiFunction: any): ConstraintValidationResult;
|
|
153
|
+
/**
|
|
154
|
+
* Get summary of fixture specs for debugging
|
|
155
|
+
*/
|
|
156
|
+
getSummary(): string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Predefined fixture templates for common patterns
|
|
160
|
+
* Builders can extend these for their specific needs
|
|
161
|
+
*/
|
|
162
|
+
export declare class FixtureTemplates {
|
|
163
|
+
/**
|
|
164
|
+
* Simple state mutation pattern
|
|
165
|
+
* For scripts that increment counters, track modifications, etc.
|
|
166
|
+
*/
|
|
167
|
+
static stateCounter(): AccountTestFixture;
|
|
168
|
+
/**
|
|
169
|
+
* Authorization pattern
|
|
170
|
+
* For scripts that check permissions via @signer
|
|
171
|
+
*/
|
|
172
|
+
static authorization(): AccountTestFixture;
|
|
173
|
+
/**
|
|
174
|
+
* Account creation pattern
|
|
175
|
+
* For scripts using @init constraint
|
|
176
|
+
*/
|
|
177
|
+
static accountCreation(): AccountTestFixture;
|
|
178
|
+
/**
|
|
179
|
+
* Multi-account transaction pattern
|
|
180
|
+
* For scripts that operate on multiple mutable accounts
|
|
181
|
+
*/
|
|
182
|
+
static batchOperation(): AccountTestFixture;
|
|
183
|
+
/**
|
|
184
|
+
* Complex authorization pattern
|
|
185
|
+
* For multi-signature or advanced permission schemes
|
|
186
|
+
*/
|
|
187
|
+
static multiSigPattern(): AccountTestFixture;
|
|
188
|
+
/**
|
|
189
|
+
* PDA pattern
|
|
190
|
+
* For scripts that use Program Derived Addresses
|
|
191
|
+
*/
|
|
192
|
+
static pdaPattern(): AccountTestFixture;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Test execution builder
|
|
196
|
+
* Combines fixture with test parameters for execution
|
|
197
|
+
*/
|
|
198
|
+
export declare class AccountTestExecutor {
|
|
199
|
+
/**
|
|
200
|
+
* Bind fixture accounts to a test execution
|
|
201
|
+
*/
|
|
202
|
+
static bindFixture(fixture: CompiledFixture, functionName: string, parameters?: any[]): AccountExecutionContext;
|
|
203
|
+
/**
|
|
204
|
+
* Validate execution context before running
|
|
205
|
+
*/
|
|
206
|
+
static validateContext(context: AccountExecutionContext): ConstraintValidationResult;
|
|
207
|
+
/**
|
|
208
|
+
* Get human-readable execution summary
|
|
209
|
+
*/
|
|
210
|
+
static getSummary(context: AccountExecutionContext): string;
|
|
211
|
+
}
|