Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BCI-2623]: removes hardcoded accounts from packages-ts/ #368

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions packages-ts/starknet-gauntlet-multisig/src/wrapper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const wrapCommand = <UI, CI>(
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)
Expand Down Expand Up @@ -269,7 +269,7 @@ export const wrapCommand = <UI, CI>(
deps.logger.success(`Tx executed at ${tx.hash}`)
}

let result = {
const result = {
responses: [
{
tx,
Expand All @@ -288,7 +288,7 @@ export const wrapCommand = <UI, CI>(

const data = await this.afterExecute(result, proposalId)

return !!data ? { ...result, data: { ...data } } : result
return data ? { ...result, data: { ...data } } : result
}
}

Expand Down
14 changes: 9 additions & 5 deletions packages-ts/starknet-gauntlet-ocr2/test/commands/ocr2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_<key>
'ocr2on_starknet_0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603731', // ocr2on_starknet_0x<key>
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions packages-ts/starknet-gauntlet-ocr2/test/commands/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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,
Expand All @@ -60,7 +64,7 @@ describe('Proxy Contract', () => {
const command = await registerExecuteCommand(deployProxyCommand).create(
{
input: {
owner: account,
owner: account.address,
address: contractAddress,
},
},
Expand All @@ -80,7 +84,7 @@ describe('Proxy Contract', () => {
const command = await registerExecuteCommand(proposeAggregatorCommand).create(
{
input: {
owner: account,
owner: account.address,
address: contractAddress,
},
},
Expand All @@ -99,7 +103,7 @@ describe('Proxy Contract', () => {
const command = await registerExecuteCommand(confirmAggregatorCommand).create(
{
input: {
owner: account,
owner: account.address,
address: contractAddress,
},
},
Expand Down
35 changes: 14 additions & 21 deletions packages-ts/starknet-gauntlet-token/test/commands/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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,
},
[],
Expand All @@ -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,
)
Expand All @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const makeExecuteCommand = <UI, CI>(config: ExecuteCommandConfig<UI, CI>)
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)
Expand Down Expand Up @@ -291,7 +291,7 @@ export const makeExecuteCommand = <UI, CI>(config: ExecuteCommandConfig<UI, CI>)
tx = await this.executeWithSigner()
}

let result = {
const result = {
responses: [
{
tx,
Expand All @@ -301,7 +301,7 @@ export const makeExecuteCommand = <UI, CI>(config: ExecuteCommandConfig<UI, CI>)
}
const data = await this.afterExecute(result)

return !!data ? { ...result, data: { ...data } } : result
return data ? { ...result, data: { ...data } } : result
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const makeInspectionCommand = <UI, CI, CompareInput, QueryResult>(
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]
Expand Down
3 changes: 1 addition & 2 deletions packages-ts/starknet-gauntlet/src/dependencies/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +15,7 @@ export interface Env {
export interface Dependencies {
logger: typeof logger
prompt: typeof prompt
makeEnv: (flags: Record<string, string | boolean>) => Env
makeEnv: (flags: Record<string, string | boolean>) => Promise<Env> | Env
makeProvider: (url: string, wallet?: IStarknetWallet) => IStarknetProvider
makeWallet: (env: Env) => Promise<IStarknetWallet>
}
Expand Down
23 changes: 5 additions & 18 deletions packages-ts/starknet-gauntlet/test/commands/execute.test.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -18,7 +9,7 @@ describe('Execute Command', () => {

type ContractInput = [string, number]

const makeUserInput = async (flags, args): Promise<UserInput> => {
const makeUserInput = async (flags): Promise<UserInput> => {
return {
a: flags.a,
b: Number(flags.b),
Expand Down Expand Up @@ -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<any, any> = {
const deployCommandConfig: ExecuteCommandConfig<unknown, unknown> = {
contractId: '',
category: 'example',
action: 'deploy',
Expand All @@ -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,
)
Expand Down
Loading
Loading