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

Upgrade starknetjs to 4.16.0 #797

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions packages/target-starknet-test/devnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
set -e
cd "$(dirname "$0")"

image=shardlabs/starknet-devnet:0.2.1
image=shardlabs/starknet-devnet:0.4.2

if [ "$(uname)" == "Darwin" ]; then
image="${image}-arm"
fi

docker rm -f devnet
exec docker run --name devnet -p 127.0.0.1:5050:5050 ${image}
exec docker run --name devnet -p 127.0.0.1:5050:5050 ${image} --seed 0
8 changes: 3 additions & 5 deletions packages/target-starknet-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
"test:fix": "pnpm lint:fix && pnpm format:fix && pnpm test && pnpm typecheck"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"concurrently": "^7.1.0",
"ganache": "^7.0.3",
"test-utils": "1.0.0",
"concurrently": "^7.6.0",
"test-utils": "workspace:1.0.0",
"typechain": "workspace:^8.1.1",
"wait-on": "^6.0.1"
},
"dependencies": {
"@types/elliptic": "^6.4.14",
"starknet": "^3.9.0"
"starknet": "^4.16.0"
}
}
37 changes: 23 additions & 14 deletions packages/target-starknet-test/test/InputReturnTypes.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import { Contract, number, Provider } from 'starknet'
import { Account, Contract, ec, json, number, SequencerProvider } from 'starknet'
const { toBN } = number
import { expect } from 'earljs'

Expand All @@ -9,25 +9,34 @@ describe('Type Transformation', () => {
let contract: _contract

before(async () => {
const provider = new Provider({ baseUrl: 'http://localhost:5050' })
const provider = new SequencerProvider({ baseUrl: 'http://localhost:5050' })

const account = new Account(
provider,
'0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a',
ec.getKeyPair('0xe3e70682c2094cac629f6fbed82c07cd'),
)

async function deployContract<C extends Contract>(
account: Account,
name: string,
calldata: any[] = [],
options: object = {},
classHash: string,
constructorCalldata: any[] = [],
): Promise<C> {
const compiledContract = JSON.parse(fs.readFileSync(`./example-abis/${name}.json`).toString('ascii'))
const response = await provider.deployContract({
contract: compiledContract,
constructorCalldata: calldata,
...options,
const contract = json.parse(fs.readFileSync(`./example-abis/${name}.json`).toString('ascii'))
const response = await account.declareDeploy({
contract,
constructorCalldata,
classHash,
})
await provider.waitForTransaction(response.transaction_hash)
const address = response.address || ''
return new Contract(compiledContract.abi, address, provider) as C
const address = response.deploy.contract_address
return new Contract(contract.abi, address, provider) as C
}

contract = await deployContract('contract')
// starkli class-hash example-abis/contract.json
const classHash = '0x022a0e662b13d18a2aaa3ee54ae290de6569621b549022c18169c6e7893809ea'
contract = await deployContract(account, 'contract', classHash)
contract.connect(account)
return contract
})

describe('Input Types', () => {
Expand Down
104 changes: 45 additions & 59 deletions packages/target-starknet-test/test/Transactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
import { expect } from 'earljs'
import fs from 'fs'
import { Account, AccountInterface, Contract, ec, Provider, TransactionStatus } from 'starknet'
import { Account, Contract, ec, json, Provider } from 'starknet'

import type { ERC20 } from '../types'

describe('Transactions', () => {
let erc20: ERC20
let account: AccountInterface
let account2: AccountInterface
let account: Account
let account2: Account
let provider: Provider

before(async () => {
const provider = new Provider({ baseUrl: 'http://localhost:5050' })
// @ts-ignore
provider = new Provider({
sequencer: { baseUrl: 'http://localhost:5050' },
})

account = new Account(
provider,
'0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a',
ec.getKeyPair('0xe3e70682c2094cac629f6fbed82c07cd'),
)

account2 = new Account(
provider,
'0x69b49c2cc8b16e80e86bfc5b0614a59aa8c9b601569c7b80dde04d3f3151b79',
ec.getKeyPair('0xf728b4fa42485e3a0a5d2f346baa9455'),
)

async function deployContract<C extends Contract>(
account: Account,
name: string,
calldata: any[] = [],
options: object = {},
classHash: string,
constructorCalldata: any[] = [],
): Promise<C> {
const compiledContract = JSON.parse(fs.readFileSync(`./example-abis/${name}.json`).toString('ascii'))
const response = await provider.deployContract({
contract: compiledContract,
constructorCalldata: calldata,
...options,
const contract = json.parse(fs.readFileSync(`./example-abis/${name}.json`).toString('ascii'))
const response = await account.declareDeploy({
contract,
constructorCalldata,
classHash,
})
await provider.waitForTransaction(response.transaction_hash)
const address = response.address || ''
return new Contract(compiledContract.abi, address, provider) as C
const address = response.deploy.contract_address
return new Contract(contract.abi, address, provider) as C
}

async function deployAccount(): Promise<Account> {
const pair = ec.genKeyPair()
const pub = ec.getStarkKey(pair)
const _ = await deployContract('ArgentAccount', [], { addressSalt: pub })
const { transaction_hash: initializeTxHash } = await _.initialize(pub, '0')
await provider.waitForTransaction(initializeTxHash)
return new Account(provider, _.address, pair)
}

account = await deployAccount()
account2 = await deployAccount()

erc20 = await deployContract('ERC20')
// starkli class-hash example-abis/ERC20.json
const erc20ClassHash = '0x02864c45bd4ba3e66d8f7855adcadf07205c88f43806ffca664f1f624765207e'
erc20 = await deployContract(account, 'ERC20', erc20ClassHash)
})

describe('via execute', () => {
it('mints', async () => {
const res = await account.execute(
const { transaction_hash } = await account.execute(
{
contractAddress: erc20.address,
entrypoint: 'mint',
Expand All @@ -54,17 +60,12 @@ describe('Transactions', () => {
[erc20.abi],
{ maxFee: '0' },
)
const response = {
address: account.address,
code: 'TRANSACTION_RECEIVED' as TransactionStatus,
result: [], // not in AddTransactionResponse
transaction_hash: res.transaction_hash,
}
expect(res).toEqual(response)
const { status } = await provider.waitForTransaction(transaction_hash)
expect(status).toEqual('ACCEPTED_ON_L2')
})

it('transfers', async () => {
const res = await account.execute(
const { transaction_hash } = await account.execute(
{
contractAddress: erc20.address,
entrypoint: 'transfer',
Expand All @@ -73,38 +74,23 @@ describe('Transactions', () => {
[erc20.abi],
{ maxFee: '0' },
)
const response = {
address: account.address,
code: 'TRANSACTION_RECEIVED' as TransactionStatus,
result: [], // not in AddTransactionResponse
transaction_hash: res.transaction_hash,
}
expect(res).toEqual(response)
const { status } = await provider.waitForTransaction(transaction_hash)
expect(status).toEqual('ACCEPTED_ON_L2')
})
})
describe('account bound', () => {
it('mints', async () => {
erc20.connect(account)
const res = await erc20.mint(account.address, 1, { maxFee: '0' })
const response = {
address: account.address,
code: 'TRANSACTION_RECEIVED' as TransactionStatus,
result: [], // not in AddTransactionResponse
transaction_hash: res.transaction_hash,
}
expect(res).toEqual(response)
const { transaction_hash } = await erc20.mint(account.address, 1, { maxFee: '0' })
const { status } = await provider.waitForTransaction(transaction_hash!)
expect(status).toEqual('ACCEPTED_ON_L2')
})

it('transfers', async () => {
erc20.connect(account)
const res = await erc20.transfer(account.address, 1, { maxFee: '0' })
const response = {
address: account.address,
code: 'TRANSACTION_RECEIVED' as TransactionStatus,
result: [], // not in AddTransactionResponse
transaction_hash: res.transaction_hash,
}
expect(res).toEqual(response)
const { transaction_hash } = await erc20.transfer(account.address, 1, { maxFee: '0' })
const { status } = await provider.waitForTransaction(transaction_hash!)
expect(status).toEqual('ACCEPTED_ON_L2')
})
})
})
Loading