Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

New contracts to declare for testing #1286

Merged
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- test(rust-rpc-test): use undeclared contracts for declare transactions testing
- build: update blockifier, fix divergent substrat block hash
- chore: remove tests that run in wasm and native, only wasm from now
- chore: split StarknetRpcApi trait in two, like in openRPC specs
Expand Down
19 changes: 9 additions & 10 deletions starknet-rpc-test/add_declare_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ async fn fail_execution_step_with_no_storage_change(madara: &ThreadSafeMadaraCli
let rpc = madara.get_starknet_client().await;

edisontim marked this conversation as resolved.
Show resolved Hide resolved
let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true);
let (declare_tx, expected_class_hash, _) =
account.declare_contract("./contracts/Counter.sierra.json", "./contracts/Counter.casm.json");
let (declare_tx, expected_class_hash, _) = account
.declare_contract("./contracts/Counter0/Counter0.sierra.json", "./contracts/Counter0/Counter0.casm.json");

let (block_number, txs) = {
let mut madara_write_lock = madara.write().await;
Expand Down Expand Up @@ -88,13 +88,12 @@ async fn fail_execution_step_with_no_storage_change(madara: &ThreadSafeMadaraCli

#[rstest]
#[tokio::test]
#[ignore = "class already declared"]
async fn works_with_storage_change(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
let rpc = madara.get_starknet_client().await;

let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true);
let (declare_tx, expected_class_hash, _) =
account.declare_contract("./contracts/Counter.sierra.json", "./contracts/Counter.casm.json");
let (declare_tx, expected_class_hash, _) = account
.declare_contract("./contracts/Counter1/Counter1.sierra.json", "./contracts/Counter1/Counter1.casm.json");

let (mut txs, block_number) = {
let mut madara_write_lock = madara.write().await;
Expand All @@ -109,7 +108,7 @@ async fn works_with_storage_change(madara: &ThreadSafeMadaraClient) -> Result<()
Ok(TransactionResult::Declaration(DeclareTransactionResult { transaction_hash, class_hash })) => {
assert_eq!(
transaction_hash,
FieldElement::from_hex_be("0x05e0f64e8140019f2657f244dd9fd136d18acc6f52d8a0b85d3f84a110d4c708")
FieldElement::from_hex_be("0x05d16c229ad76e91113b3216bd05b5cf3362c80967aaa3e4317bc48a0257b160")
edisontim marked this conversation as resolved.
Show resolved Hide resolved
.unwrap()
);
assert_eq!(class_hash, expected_class_hash);
Expand All @@ -134,8 +133,8 @@ async fn fails_already_declared(madara: &ThreadSafeMadaraClient) -> Result<(), a

edisontim marked this conversation as resolved.
Show resolved Hide resolved
// first declaration works
let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true);
let (declare_tx, _, _) =
account.declare_contract("./contracts/Counter.sierra.json", "./contracts/Counter.casm.json");
let (declare_tx, _, _) = account
.declare_contract("./contracts/Counter2/Counter2.sierra.json", "./contracts/Counter2/Counter2.casm.json");

let mut madara_write_lock = madara.write().await;
// The first one will fail too for now
Expand All @@ -145,8 +144,8 @@ async fn fails_already_declared(madara: &ThreadSafeMadaraClient) -> Result<(), a
assert!(txs[0].as_ref().is_ok());

// second declaration fails
let (declare_tx, _, _) =
account.declare_contract("./contracts/Counter.sierra.json", "./contracts/Counter.casm.json");
let (declare_tx, _, _) = account
.declare_contract("./contracts/Counter2/Counter2.sierra.json", "./contracts/Counter2/Counter2.casm.json");

let mut txs = madara_write_lock.create_block_with_txs(vec![Transaction::Declaration(declare_tx)]).await?;

Expand Down
24 changes: 12 additions & 12 deletions starknet-rpc-test/add_deploy_account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ async fn works_with_storage_change(madara: &ThreadSafeMadaraClient) -> Result<()

let (mut txs, block_number) = {
let mut madara_write_lock = madara.write().await;
let txs = madara_write_lock
.create_block_with_txs(vec![
Transaction::Execution(funding_account.transfer_tokens(
account_address,
FieldElement::from_hex_be(MAX_FEE_OVERRIDE).unwrap(),
None,
)),
Transaction::AccountDeployment(account_deploy_txn),
])
// If we group the funding of the account and the deployment in one block for some unknown reason
// the account_address isn't found in the get_class_hash_at later
let mut txs = madara_write_lock
.create_block_with_txs(vec![Transaction::Execution(funding_account.transfer_tokens(
account_address,
FieldElement::from_hex_be(MAX_FEE_OVERRIDE).unwrap(),
None,
))])
.await?;
let mut second_tx =
madara_write_lock.create_block_with_txs(vec![Transaction::AccountDeployment(account_deploy_txn)]).await?;
let block_number = rpc.block_number().await?;

let _ = &txs.append(&mut second_tx);
(txs, block_number)
};

assert_eq!(txs.len(), 2);
let account_deploy_tx_result = txs.remove(1);
match account_deploy_tx_result {
Expand All @@ -102,7 +102,7 @@ async fn works_with_storage_change(madara: &ThreadSafeMadaraClient) -> Result<()

// included in block
let included_txs = rpc.get_block_transaction_count(BlockId::Number(block_number)).await?;
assert_eq!(included_txs, 2); // fund transfer + deploy
assert_eq!(included_txs, 1); // Decomposed into 2 blocks

Ok(())
}
19 changes: 19 additions & 0 deletions starknet-rpc-test/contracts/Counter0/Counter0.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[starknet::contract]
mod Counter0 {
#[storage]
struct Storage {
balance_0: felt252,
}

// Increases the balance_0 by the given amount.
#[external(v0)]
fn increase_balance_0(ref self: ContractState, amount: felt252) {
self.balance_0.write(self.balance_0.read() + amount + 0 + 1);
}

// Returns the current balance_0.
#[external(v0)]
fn get_balance_0(self: @ContractState) -> felt252 {
self.balance_0.read()
}
}
Loading