Skip to content

Commit

Permalink
feat: getNonce fails for uninitialized accounts (keep-starknet-strang…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbelleng authored Jan 17, 2024
1 parent 8c285b4 commit 2b96865
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers-contrib/features/protoc-asdf:1": {}
"ghcr.io/devcontainers-contrib/features/protoc-asdf:1": {},
},
"hostRequirements": {
"cpus": 8,
"memory": "16gb",
"storage": "128gb"
}
"storage": "128gb",
},
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
- fix: `tempdir` crate has been deprecated; use `tempfile` instead
- dev: add avail and celestia crates behind a feature flag
- dev: replace md5 with sha3_256 hash function
- feat: fixing getNonce Rpc Call and adding a new test

## v0.6.0

Expand Down
2 changes: 2 additions & 0 deletions crates/client/storage/src/overrides/schema_v1_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ where
}

fn nonce(&self, block_hash: <B as BlockT>::Hash, address: ContractAddress) -> Option<Nonce> {
self.contract_class_hash_by_address(block_hash, address)?;

let storage_nonce_prefix = storage_prefix_build(PALLET_STARKNET, STARKNET_NONCE);
let nonce = self.query_storage::<Nonce>(
block_hash,
Expand Down
11 changes: 4 additions & 7 deletions starknet-rpc-test/get_block_with_txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ async fn works_with_deploy_account_txn(madara: &ThreadSafeMadaraClient) -> Resul
let contract_address_salt = FieldElement::ONE;
let max_fee = FieldElement::from_hex_be(MAX_FEE_OVERRIDE).unwrap();

let (deploy_nonce, block) = {
let block = {
let mut madara_write_lock = madara.write().await;
let oz_factory = build_oz_account_factory(&rpc, "0x123", class_hash).await;
let account_deploy_txn = build_deploy_account_tx(&oz_factory, FieldElement::ONE);

let funding_account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true);
let account_address = account_deploy_txn.address();
let deploy_nonce = rpc.get_nonce(BlockId::Tag(BlockTag::Latest), account_deploy_txn.address()).await?;

// We execute the funding in a different block, because we have no way to guarantee the tx execution
// order once in the mempool
Expand All @@ -122,20 +121,18 @@ async fn works_with_deploy_account_txn(madara: &ThreadSafeMadaraClient) -> Resul

madara_write_lock.create_block_with_txs(vec![Transaction::AccountDeployment(account_deploy_txn)]).await?;

let block = match rpc.get_block_with_txs(BlockId::Tag(BlockTag::Latest)).await.unwrap() {
match rpc.get_block_with_txs(BlockId::Tag(BlockTag::Latest)).await.unwrap() {
MaybePendingBlockWithTxs::Block(block) => block,
MaybePendingBlockWithTxs::PendingBlock(_) => return Err(anyhow!("Expected block, got pending block")),
};

(deploy_nonce, block)
}
};

assert_eq!(block.transactions.len(), 1);
let tx = match &block.transactions[0] {
StarknetTransaction::DeployAccount(tx) => tx,
_ => return Err(anyhow!("Expected an deploy transaction v1")),
};
assert_eq!(tx.nonce, deploy_nonce);
assert_eq!(tx.nonce, 0u8.into());
assert_eq!(tx.max_fee, max_fee);
assert_eq!(tx.contract_address_salt, contract_address_salt);
assert_eq!(tx.class_hash, class_hash);
Expand Down
15 changes: 8 additions & 7 deletions starknet-rpc-test/get_nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ async fn fail_non_existing_block(madara: &ThreadSafeMadaraClient) -> Result<(),

#[rstest]
#[tokio::test]
async fn work_ok_non_used_contract_address(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
async fn fail_non_existing_contract(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
let rpc = madara.get_starknet_client().await;

assert_eq!(
rpc.get_nonce(
BlockId::Number(0),
FieldElement::from_hex_be("0x4269DEADBEEF").expect("Invalid Contract Address")
assert_matches!(
rpc
.get_nonce(
BlockId::Tag(BlockTag::Latest),
FieldElement::from_hex_be("0x51e59c2c182a58fb0a74349bfa4769cbbcba32547591dd3fb1def8623997d00").unwrap(),
)
.await?,
FieldElement::ZERO
.await,
Err(ProviderError::StarknetError(StarknetErrorWithMessage { code: MaybeUnknownErrorCode::Known(code), .. })) if code == StarknetError::ContractNotFound
);

Ok(())
Expand Down

0 comments on commit 2b96865

Please sign in to comment.