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

feat: speedup e2e #1912

Merged
merged 1 commit into from
Mar 15, 2023
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
68 changes: 57 additions & 11 deletions packages/extension/src/background/devnet/declareAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { memoize } from "lodash-es"
import { Account, AccountInterface, ec } from "starknet"
import { hash } from "starknet5"
import urlJoin from "url-join"

import { Network, getProvider } from "../../shared/network"
Expand Down Expand Up @@ -44,20 +45,65 @@ export const declareContracts = memoize(
_loadContracts: LoadContracts,
) => {
const [proxyContract, accountContract] = await _loadContracts()
const proxy = await deployAccount.declare({
classHash: PROXY_CONTRACT_CLASS_HASHES[0],
contract: proxyContract,
})

const account = await deployAccount.declare({
classHash: ARGENT_ACCOUNT_CONTRACT_CLASS_HASHES[0],
contract: accountContract,
})
let proxyClassHash: string | undefined
let accountClassHash: string | undefined

await deployAccount.waitForTransaction(account.transaction_hash, 1e3)
await deployAccount.waitForTransaction(proxy.transaction_hash, 1e3)
const computedProxyClassHash = hash.computeContractClassHash(proxyContract)
const computedAccountClassHash =
hash.computeContractClassHash(accountContract)

return { proxy, account }
const isProxyClassDeclared = await checkIfClassIsDeclared(
deployAccount,
computedProxyClassHash,
)

const isAccountClassDeclared = await checkIfClassIsDeclared(
deployAccount,
computedAccountClassHash,
)

if (!isProxyClassDeclared) {
const proxy = await deployAccount.declare({
classHash: PROXY_CONTRACT_CLASS_HASHES[0],
contract: proxyContract,
})

await deployAccount.waitForTransaction(proxy.transaction_hash, 1e3)

proxyClassHash = proxy.class_hash
}

if (!isAccountClassDeclared) {
const account = await deployAccount.declare({
classHash: ARGENT_ACCOUNT_CONTRACT_CLASS_HASHES[0],
contract: accountContract,
})

await deployAccount.waitForTransaction(account.transaction_hash, 1e3)

accountClassHash = account.class_hash
}

return {
proxyClassHash: proxyClassHash ?? computedProxyClassHash,
accountClassHash: accountClassHash ?? computedAccountClassHash,
}
},
(network) => `${network.baseUrl}`,
)

export const checkIfClassIsDeclared = async (
account: AccountInterface,
classHash: string,
) => {
try {
const contract = await account.getClassByHash(classHash)

console.log("Contract already declared", classHash)
return Boolean(contract)
} catch (error) {
console.warn("Contract not declared", classHash)
return false
}
}
4 changes: 2 additions & 2 deletions packages/extension/src/background/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ export class Wallet {

const deployerAccount = await getPreDeployedAccount(network)
if (deployerAccount) {
const { account } = await declareContracts(
const { accountClassHash } = await declareContracts(
network,
deployerAccount,
this.loadContracts,
)

return account.class_hash
return accountClassHash
}

return ARGENT_ACCOUNT_CONTRACT_CLASS_HASHES[0]
Expand Down