diff --git a/contracts/Scarb.lock b/contracts/Scarb.lock index 2ba9d1f72..9d2d099e8 100644 --- a/contracts/Scarb.lock +++ b/contracts/Scarb.lock @@ -11,4 +11,4 @@ dependencies = [ [[package]] name = "openzeppelin" version = "0.9.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.9.0#861fc416f87addbe23a3b47f9d19ab27c10d5dc8" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.9.0#364db5b1aecc1335d2e65db887291d19aa28937d" diff --git a/packages-ts/starknet-gauntlet-multisig/src/wrapper/index.ts b/packages-ts/starknet-gauntlet-multisig/src/wrapper/index.ts index 8d853fbd2..b75105b1a 100644 --- a/packages-ts/starknet-gauntlet-multisig/src/wrapper/index.ts +++ b/packages-ts/starknet-gauntlet-multisig/src/wrapper/index.ts @@ -75,7 +75,7 @@ export const wrapCommand = ( static create = async (flags, args) => { const c = new MsigCommand(flags, args) - const env = deps.makeEnv(flags) + const env = await deps.makeEnv(flags) c.wallet = await deps.makeWallet(env) c.provider = deps.makeProvider(env.providerUrl, c.wallet) @@ -269,7 +269,7 @@ export const wrapCommand = ( deps.logger.success(`Tx executed at ${tx.hash}`) } - let result = { + const result = { responses: [ { tx, @@ -288,7 +288,7 @@ export const wrapCommand = ( const data = await this.afterExecute(result, proposalId) - return !!data ? { ...result, data: { ...data } } : result + return data ? { ...result, data: { ...data } } : result } } diff --git a/packages-ts/starknet-gauntlet-ocr2/test/commands/ocr2.test.ts b/packages-ts/starknet-gauntlet-ocr2/test/commands/ocr2.test.ts index 7101dbd86..1ecc87001 100644 --- a/packages-ts/starknet-gauntlet-ocr2/test/commands/ocr2.test.ts +++ b/packages-ts/starknet-gauntlet-ocr2/test/commands/ocr2.test.ts @@ -7,14 +7,13 @@ import { registerExecuteCommand, TIMEOUT, LOCAL_URL, - devnetAccount0Address, + StarknetAccount, + fetchAccount, } from '@chainlink/starknet-gauntlet/test/utils' import { loadContract } from '@chainlink/starknet-gauntlet' import { CONTRACT_LIST } from '../../src/lib/contracts' import { Contract, InvokeTransactionReceiptResponse } from 'starknet' -let account = devnetAccount0Address - const signers = [ 'ocr2on_starknet_04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603730', // ocr2on_starknet_ 'ocr2on_starknet_0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603731', // ocr2on_starknet_0x @@ -73,9 +72,14 @@ const validInput = { } describe('OCR2 Contract', () => { + let account: StarknetAccount let contractAddress: string let accessController: string + beforeAll(async () => { + account = await fetchAccount() + }) + it( 'Deploy AC', async () => { @@ -95,7 +99,7 @@ describe('OCR2 Contract', () => { const command = await registerExecuteCommand(deployCommand).create( { input: { - owner: account, + owner: account.address, maxAnswer: 10000, minAnswer: 1, decimals: 18, @@ -174,7 +178,7 @@ describe('OCR2 Contract', () => { // TODO: use StarknetContract decodeEvents from starknet-hardhat-plugin instead const eventData = receipt.events[0].data // reconstruct signers array from event - let eventSigners: bigint[] = [] + const eventSigners: bigint[] = [] for (let i = 0; i < signers.length; i++) { const signer = BigInt(eventData[4 + 2 * i]) // split according to event structure eventSigners.push(signer) diff --git a/packages-ts/starknet-gauntlet-ocr2/test/commands/proxy.test.ts b/packages-ts/starknet-gauntlet-ocr2/test/commands/proxy.test.ts index ebaead41d..ffc6506e1 100644 --- a/packages-ts/starknet-gauntlet-ocr2/test/commands/proxy.test.ts +++ b/packages-ts/starknet-gauntlet-ocr2/test/commands/proxy.test.ts @@ -4,18 +4,22 @@ import deployProxyCommand from '../../src/commands/proxy/deploy' import proposeAggregatorCommand from '../../src/commands/proxy/proposeAggregator' import confirmAggregatorCommand from '../../src/commands/proxy/confirmAggregator' import { + StarknetAccount, + fetchAccount, registerExecuteCommand, TIMEOUT, - devnetAccount0Address, } from '@chainlink/starknet-gauntlet/test/utils' -let account = devnetAccount0Address - describe('Proxy Contract', () => { + let account: StarknetAccount let contractAddress: string let accessController: string let proxy: string + beforeAll(async () => { + account = await fetchAccount() + }) + it( 'Deploy AC', async () => { @@ -35,7 +39,7 @@ describe('Proxy Contract', () => { const command = await registerExecuteCommand(deployOCR2Command).create( { input: { - owner: account, + owner: account.address, maxAnswer: 10000, minAnswer: 1, decimals: 18, @@ -60,7 +64,7 @@ describe('Proxy Contract', () => { const command = await registerExecuteCommand(deployProxyCommand).create( { input: { - owner: account, + owner: account.address, address: contractAddress, }, }, @@ -80,7 +84,7 @@ describe('Proxy Contract', () => { const command = await registerExecuteCommand(proposeAggregatorCommand).create( { input: { - owner: account, + owner: account.address, address: contractAddress, }, }, @@ -99,7 +103,7 @@ describe('Proxy Contract', () => { const command = await registerExecuteCommand(confirmAggregatorCommand).create( { input: { - owner: account, + owner: account.address, address: contractAddress, }, }, diff --git a/packages-ts/starknet-gauntlet-token/test/commands/token.test.ts b/packages-ts/starknet-gauntlet-token/test/commands/token.test.ts index bdeb2601b..e1b779fc4 100644 --- a/packages-ts/starknet-gauntlet-token/test/commands/token.test.ts +++ b/packages-ts/starknet-gauntlet-token/test/commands/token.test.ts @@ -3,31 +3,25 @@ import deployTokenCommand from '../../src/commands/token/deploy' import mintTokensCommand from '../../src/commands/token/mint' import transferTokensCommand from '../../src/commands/token/transfer' import balanceOfCommand from '../../src/commands/inspection/balanceOf' - import { + StarknetAccount, + fetchAccount, registerExecuteCommand, registerInspectCommand, - devnetAccount0Address, - devnetPrivateKey, TIMEOUT, } from '@chainlink/starknet-gauntlet/test/utils' describe('Token Contract', () => { - let defaultAccount: string - let defaultPk: string - let defaultBalance: number + let defaultAccount: StarknetAccount let ozAccount: string - let ozPk: string let ozBalance: number let tokenContractAddress: string beforeAll(async () => { // account #0 with seed 0 - defaultAccount = devnetAccount0Address - defaultPk = devnetPrivateKey - defaultBalance = 0 + defaultAccount = await fetchAccount() }, TIMEOUT) it( @@ -39,7 +33,6 @@ describe('Token Contract', () => { expect(report.responses[0].tx.status).toEqual('ACCEPTED') ozAccount = report.responses[0].contract - ozPk = report.data.privateKey ozBalance = 0 }, TIMEOUT, @@ -50,8 +43,8 @@ describe('Token Contract', () => { async () => { const command = await registerExecuteCommand(deployTokenCommand).create( { - account: defaultAccount, - pk: defaultPk, + account: defaultAccount.address, + pk: defaultAccount.privateKey, link: true, }, [], @@ -72,25 +65,25 @@ describe('Token Contract', () => { const executeCommand = await registerExecuteCommand(mintTokensCommand).create( { - account: defaultAccount, - pk: defaultPk, - recipient: defaultAccount, + account: defaultAccount.address, + pk: defaultAccount.privateKey, + recipient: defaultAccount.address, amount, }, [tokenContractAddress], ) let report = await executeCommand.execute() expect(report.responses[0].tx.status).toEqual('ACCEPTED') - defaultBalance = amount + defaultAccount.balance = amount const inspectCommand = await registerInspectCommand(balanceOfCommand).create( { - address: defaultAccount, + address: defaultAccount.address, }, [tokenContractAddress], ) report = await inspectCommand.execute() - expect(report.data?.data?.balance).toEqual(defaultBalance.toString()) + expect(report.data?.data?.balance).toEqual(defaultAccount.balance.toString()) }, TIMEOUT, ) @@ -102,8 +95,8 @@ describe('Token Contract', () => { const executeCommand = await registerExecuteCommand(transferTokensCommand).create( { - account: defaultAccount, - pk: defaultPk, + account: defaultAccount.address, + pk: defaultAccount.privateKey, recipient: ozAccount, amount, }, diff --git a/packages-ts/starknet-gauntlet/src/commands/base/executeCommand.ts b/packages-ts/starknet-gauntlet/src/commands/base/executeCommand.ts index 8fc256ebd..90b0f1ced 100644 --- a/packages-ts/starknet-gauntlet/src/commands/base/executeCommand.ts +++ b/packages-ts/starknet-gauntlet/src/commands/base/executeCommand.ts @@ -98,7 +98,7 @@ export const makeExecuteCommand = (config: ExecuteCommandConfig) static create = async (flags, args) => { const c = new ExecuteCommand(flags, args) - const env = deps.makeEnv(flags) + const env = await deps.makeEnv(flags) c.wallet = await deps.makeWallet(env) c.provider = deps.makeProvider(env.providerUrl, c.wallet) @@ -291,7 +291,7 @@ export const makeExecuteCommand = (config: ExecuteCommandConfig) tx = await this.executeWithSigner() } - let result = { + const result = { responses: [ { tx, @@ -301,7 +301,7 @@ export const makeExecuteCommand = (config: ExecuteCommandConfig) } const data = await this.afterExecute(result) - return !!data ? { ...result, data: { ...data } } : result + return data ? { ...result, data: { ...data } } : result } } diff --git a/packages-ts/starknet-gauntlet/src/commands/base/inspectionCommand.ts b/packages-ts/starknet-gauntlet/src/commands/base/inspectionCommand.ts index 38f2dbef9..1ef8998fb 100644 --- a/packages-ts/starknet-gauntlet/src/commands/base/inspectionCommand.ts +++ b/packages-ts/starknet-gauntlet/src/commands/base/inspectionCommand.ts @@ -88,7 +88,7 @@ export const makeInspectionCommand = ( static create = async (flags, args) => { const c = new InspectionCommand(flags, args) - const env = deps.makeEnv(flags) + const env = await deps.makeEnv(flags) c.provider = deps.makeProvider(env.providerUrl) c.contractAddress = args[0] diff --git a/packages-ts/starknet-gauntlet/src/dependencies/index.ts b/packages-ts/starknet-gauntlet/src/dependencies/index.ts index 1ab7f0267..bddc4edfd 100644 --- a/packages-ts/starknet-gauntlet/src/dependencies/index.ts +++ b/packages-ts/starknet-gauntlet/src/dependencies/index.ts @@ -1,7 +1,6 @@ import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils' import { IStarknetProvider } from '../provider' import { IStarknetWallet } from '../wallet' -import { makeProvider } from '@chainlink/evm-gauntlet' export interface Env { providerUrl: string @@ -16,7 +15,7 @@ export interface Env { export interface Dependencies { logger: typeof logger prompt: typeof prompt - makeEnv: (flags: Record) => Env + makeEnv: (flags: Record) => Promise | Env makeProvider: (url: string, wallet?: IStarknetWallet) => IStarknetProvider makeWallet: (env: Env) => Promise } diff --git a/packages-ts/starknet-gauntlet/test/commands/execute.test.ts b/packages-ts/starknet-gauntlet/test/commands/execute.test.ts index 1a6152e79..cb319a45e 100644 --- a/packages-ts/starknet-gauntlet/test/commands/execute.test.ts +++ b/packages-ts/starknet-gauntlet/test/commands/execute.test.ts @@ -1,14 +1,5 @@ +import { loadExampleContract, registerExecuteCommand, TIMEOUT } from '../utils' import { ExecuteCommandConfig, makeExecuteCommand } from '../../src/index' -import { - devnetAccount0Address, - devnetPrivateKey, - loadExampleContract, - registerExecuteCommand, - TIMEOUT, -} from '../utils' - -let account: string = devnetAccount0Address -let privateKey: string = devnetPrivateKey describe('Execute Command', () => { type UserInput = { @@ -18,7 +9,7 @@ describe('Execute Command', () => { type ContractInput = [string, number] - const makeUserInput = async (flags, args): Promise => { + const makeUserInput = async (flags): Promise => { return { a: flags.a, b: Number(flags.b), @@ -64,20 +55,18 @@ describe('Execute Command', () => { }) describe('Execute with network', () => { - let contractAddress: string - it( 'Command deploy execution', async () => { - const makeUserInput = async (flags, args) => { + const makeUserInput = async () => { return } - const makeContractInput = async (userInput) => { + const makeContractInput = async () => { return {} } - const deployCommandConfig: ExecuteCommandConfig = { + const deployCommandConfig: ExecuteCommandConfig = { contractId: '', category: 'example', action: 'deploy', @@ -96,8 +85,6 @@ describe('Execute with network', () => { const commandInstance = await command.create({}, []) const report = await commandInstance.execute() expect(report.responses[0].tx.status).toEqual('ACCEPTED') - - contractAddress = report.responses[0].contract }, TIMEOUT, ) diff --git a/packages-ts/starknet-gauntlet/test/utils/index.ts b/packages-ts/starknet-gauntlet/test/utils/index.ts index 373ab5769..7406d368c 100644 --- a/packages-ts/starknet-gauntlet/test/utils/index.ts +++ b/packages-ts/starknet-gauntlet/test/utils/index.ts @@ -14,7 +14,7 @@ export const loadContract = (name: string): CompiledContract => { return json.parse(fs.readFileSync(`${__dirname}/../__mocks__/${name}.json`).toString('ascii')) } -export const loadExampleContract = (): any => { +export const loadExampleContract = () => { return { contract: loadContract('example') } } @@ -38,10 +38,23 @@ export const noopPrompt: typeof prompt = async () => {} export const TIMEOUT = 900000 export const LOCAL_URL = 'http://127.0.0.1:5050/' -export const devnetPrivateKey = '0x71d7bb07b9a64f6f78ac4c816aff4da9' -export const devnetAccount0Address = - '0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691' -// export const devnetKeyPair = ec.getKeyPair(devnetPrivateKey); + +export type StarknetAccount = Awaited> +export const fetchAccount = async (accountIndex = 0) => { + const response = await fetch(`${LOCAL_URL}predeployed_accounts`) + const accounts = await response.json() + + const account = accounts.at(accountIndex) + if (account == null) { + throw new Error('no accounts available') + } + + return { + address: account.address as string, + privateKey: account.private_key as string, + balance: parseInt(account.initial_balance, 10), + } +} export const registerExecuteCommand = ( registerCommand: (deps: Dependencies) => CommandCtor>, @@ -49,11 +62,17 @@ export const registerExecuteCommand = ( const deps: Dependencies = { logger: noopLogger, prompt: noopPrompt, - makeEnv: (flags) => { + makeEnv: async (flags) => { + if (flags.pk == null || flags.account == null) { + const acct = await fetchAccount() + flags.account = flags.account ?? acct.address + flags.pk = flags.pk ?? acct.privateKey + } + return { providerUrl: LOCAL_URL, - pk: (flags.pk as string) || devnetPrivateKey, - account: (flags.account as string) || devnetAccount0Address, + pk: flags.pk as string, + account: flags.account as string, } }, makeProvider: makeProvider, @@ -70,11 +89,17 @@ export const registerInspectCommand = ( const deps: Omit = { logger: noopLogger, prompt: noopPrompt, - makeEnv: (flags) => { + makeEnv: async (flags) => { + if (flags.pk == null || flags.account == null) { + const acct = await fetchAccount() + flags.account = flags.accout ?? acct.address + flags.pk = flags.pk ?? acct.privateKey + } + return { providerUrl: LOCAL_URL, - pk: (flags.pk as string) || devnetPrivateKey, - account: (flags.account as string) || devnetAccount0Address, + pk: flags.pk as string, + account: flags.account as string, } }, makeProvider: makeProvider,