Skip to content

Commit

Permalink
Merge pull request #30 from casper-ecosystem/update_deps
Browse files Browse the repository at this point in the history
Fix build: Updated dependencies, Rust toolchain, and comments
  • Loading branch information
sczembor authored Mar 11, 2024
2 parents 57e3912 + f8c34b2 commit 1f72b94
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 47 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci-casper-rust-contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: ci-casper-rust-contract

on:
push:
branches: [ master ]
branches: [master]
paths-ignore:
- '**.md'
- "**.md"

pull_request:
branches: [ master ]
branches: [master]
paths-ignore:
- '**.md'
- "**.md"

jobs:
build:
Expand All @@ -18,13 +18,13 @@ jobs:
os: [ubuntu-20.04, ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustfmt, clippy
# Needed for gcc install
- run: sudo apt update && sudo apt install -y build-essential
- run: make prepare
- run: make check-lint
- run: make test
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustfmt, clippy
# Needed for gcc install
- run: sudo apt update && sudo apt install -y build-essential
- run: make prepare
- run: make check-lint
- run: make test
6 changes: 3 additions & 3 deletions contract-v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["CasperLabs <https://discord.com/invite/Q38s3Vh>"]
edition = "2021"

[dependencies]
casper-contract = "1.4.4"
casper-types = "1.5.0"
casper-contract = "3.0.0"
casper-types = "3.0.0"

[[bin]]
name = "counter-v1"
Expand All @@ -15,4 +15,4 @@ bench = false
doctest = false
test = false

[profile.release] #reduces Wasm size
[profile.release] #reduces Wasm size
12 changes: 6 additions & 6 deletions contract-v1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ use casper_types::{
CLType, CLValue, URef,
};

// Constants for the keys pointing to values stored in the account's named keys.
/// Constants for the keys pointing to values stored in the account's named keys.
const CONTRACT_PACKAGE_NAME: &str = "counter_package_name";
const CONTRACT_ACCESS_UREF: &str = "counter_access_uref";

// Creating constants for the various contract entry points.
/// Creating constants for the various contract entry points.
const ENTRY_POINT_COUNTER_INC: &str = "counter_inc";
const ENTRY_POINT_COUNTER_GET: &str = "counter_get";

// Constants for the keys pointing to values stored in the contract's named keys.
/// Constants for the keys pointing to values stored in the contract's named keys.
const CONTRACT_VERSION_KEY: &str = "version";
const CONTRACT_KEY: &str = "counter";
const COUNT_KEY: &str = "count";

// Entry point that increments the count value by 1.
/// Entry point that increments the count value by 1.
#[no_mangle]
pub extern "C" fn counter_inc() {
let uref: URef = runtime::get_key(COUNT_KEY)
Expand All @@ -46,7 +46,7 @@ pub extern "C" fn counter_inc() {
storage::add(uref, 1); // Increment the count by 1.
}

// Entry point that returns the count value.
/// Entry point that returns the count value.
#[no_mangle]
pub extern "C" fn counter_get() {
let uref: URef = runtime::get_key(COUNT_KEY)
Expand All @@ -60,7 +60,7 @@ pub extern "C" fn counter_get() {
runtime::ret(typed_result); // Return the count value.
}

// Entry point that executes automatically when a caller installs the contract.
/// Entry point that executes automatically when a caller installs the contract.
#[no_mangle]
pub extern "C" fn call() {
// Initialize the count to 0, locally.
Expand Down
4 changes: 2 additions & 2 deletions contract-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "1.0.0"
edition = "2021"

[dependencies]
casper-contract = "1.4.4"
casper-types = "1.5.0"
casper-contract = "3.0.0"
casper-types = "3.0.0"

[[bin]]
name = "counter-v2"
Expand Down
18 changes: 9 additions & 9 deletions contract-v2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ use casper_types::{
CLType, CLValue, URef,
};

// Creating constants for the various contract entry points.
/// Creating constants for the various contract entry points.
const ENTRY_POINT_COUNTER_INC: &str = "counter_inc";
const ENTRY_POINT_COUNTER_GET: &str = "counter_get";
const ENTRY_POINT_COUNTER_DECREMENT: &str = "counter_decrement";

// Constants for the keys pointing to values stored in the contract's named keys.
/// Constants for the keys pointing to values stored in the contract's named keys.
const CONTRACT_VERSION_KEY: &str = "version";
const CONTRACT_KEY: &str = "counter";
const COUNT_KEY: &str = "count";

// Constants for the keys pointing to values stored in the account's named keys.
/// Constants for the keys pointing to values stored in the account's named keys.
const CONTRACT_PACKAGE_NAME: &str = "counter_package_name";
const CONTRACT_ACCESS_UREF: &str = "counter_access_uref";

// Entry point that increments the count value by 1.
/// Entry point that increments the count value by 1.
#[no_mangle]
pub extern "C" fn counter_inc() {
let uref: URef = runtime::get_key(COUNT_KEY)
Expand All @@ -48,7 +48,7 @@ pub extern "C" fn counter_inc() {
storage::add(uref, 1); // Increment the count by 1.
}

// Entry point that returns the count value.
/// Entry point that returns the count value.
#[no_mangle]
pub extern "C" fn counter_get() {
let uref: URef = runtime::get_key(COUNT_KEY)
Expand All @@ -62,7 +62,7 @@ pub extern "C" fn counter_get() {
runtime::ret(typed_result); // Return the count value.
}

// Entry point that decrements the count value by 1.
/// Entry point that decrements the count value by 1.
#[no_mangle]
pub extern "C" fn counter_decrement() {
let uref: URef = runtime::get_key(COUNT_KEY)
Expand All @@ -72,7 +72,7 @@ pub extern "C" fn counter_decrement() {
storage::add(uref, -1); // Decrement the count.
}

// Helper function that installs the counter contract on chain.
/// Helper function that installs the counter contract on chain.
fn install_counter() {
// Initialize the count to 0, locally.
let count_start = storage::new_uref(0_i32);
Expand Down Expand Up @@ -121,7 +121,7 @@ fn install_counter() {
runtime::put_key(CONTRACT_KEY, stored_contract_hash.into());
}

// Helper function that upgrades the contract package to a new version.
/// Helper function that upgrades the contract package to a new version.
fn upgrade_counter() {
// In this version, we will not add any named keys.
// The named keys from the previous version should still be available.
Expand Down Expand Up @@ -178,7 +178,7 @@ fn upgrade_counter() {
runtime::put_key(CONTRACT_KEY, stored_contract_hash.into());
}

// Entry point that executes automatically when a caller installs the contract.
/// Entry point that executes automatically when a caller installs the contract.
#[no_mangle]
pub extern "C" fn call() {
match runtime::get_key(CONTRACT_ACCESS_UREF) {
Expand Down
4 changes: 2 additions & 2 deletions counter-call/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["CasperLabs <https://discord.com/invite/Q38s3Vh>"]
edition = "2021"

[dependencies]
casper-contract = "1.4.4"
casper-types = "1.5.0"
casper-contract = "3.0.0"
casper-types = "3.0.0"

[[bin]]
name = "counter-call"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2022-03-17
nightly-2023-03-25
6 changes: 3 additions & 3 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ authors = ["CasperLabs <https://discord.com/invite/Q38s3Vh>"]
edition = "2021"

[dependencies]
casper-engine-test-support = { version = "2.2.0", features = ["test-support"] }
casper-execution-engine = "2.0.0"
casper-types = "1.5.0"
casper-engine-test-support = { version = "5.0.0", features = ["test-support"] }
casper-execution-engine = "5.0.0"
casper-types = "3.0.0"

[[bin]]
name = "integration-tests"
Expand Down
20 changes: 13 additions & 7 deletions tests/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod tests {
// Outlining aspects of the Casper test support crate to include.
use casper_engine_test_support::{
ExecuteRequestBuilder, InMemoryWasmTestBuilder, DEFAULT_ACCOUNT_ADDR,
DEFAULT_RUN_GENESIS_REQUEST,
PRODUCTION_RUN_GENESIS_REQUEST,
};
// Custom Casper types that will be used within this test.
use casper_types::{runtime_args, ContractHash, RuntimeArgs};
Expand All @@ -19,7 +19,6 @@ mod tests {
const ENTRY_POINT_COUNTER_DECREMENT: &str = "counter_decrement"; // Entry point to decrement the count value
const ENTRY_POINT_COUNTER_INC: &str = "counter_inc"; // Entry point to increment the count value

#[test]
/// Install version 1 of the counter contract and check its available entry points.
/// Only the increment entry point should be available.
/// The decrement call should fail, because that entry point should not be in this version.
Expand All @@ -32,9 +31,12 @@ mod tests {
/// - Verify that the count value is now 1.
/// - Call the decrement entry point, which should fail.
/// - Ensure the count value was not decremented and is still 1.
#[test]
fn install_version1_and_check_entry_points() {
let mut builder = InMemoryWasmTestBuilder::default();
builder.run_genesis(&*DEFAULT_RUN_GENESIS_REQUEST).commit();
builder
.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST)
.commit();

// Install the contract.
let contract_v1_installation_request = ExecuteRequestBuilder::standard(
Expand Down Expand Up @@ -153,7 +155,6 @@ mod tests {
assert_eq!(current_count, 1);
}

#[test]
/// Install version 1 of the counter contract and check its functionality.
/// Then, upgrade the contract by installing a second Wasm for version 2.
/// Check the functionality of the second version.
Expand All @@ -171,9 +172,12 @@ mod tests {
/// - Verify the new contract version is 2.
/// - Increment the counter to check that counter_inc is still working after the upgrade. Count is now 2.
/// - Call the decrement entry point and verify that the count is now 1.
#[test]
fn install_version1_and_upgrade_to_version2() {
let mut builder = InMemoryWasmTestBuilder::default();
builder.run_genesis(&*DEFAULT_RUN_GENESIS_REQUEST).commit();
builder
.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST)
.commit();

// Install the first version of the contract.
let contract_v1_installation_request = ExecuteRequestBuilder::standard(
Expand Down Expand Up @@ -381,7 +385,6 @@ mod tests {
assert_eq!(decremented_count, 1);
}

#[test]
/// Install version 2 of the counter contract without having version 1 already on chain.
/// Test summary:
/// - Install the counter-v2.wasm contract.
Expand All @@ -392,9 +395,12 @@ mod tests {
/// - Verify that the count value is now 1.
/// - Call the decrement entry point, which should succeed.
/// - Verify that the count is 0.
#[test]
fn install_version2_directly_without_version1() {
let mut builder = InMemoryWasmTestBuilder::default();
builder.run_genesis(&*DEFAULT_RUN_GENESIS_REQUEST).commit();
builder
.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST)
.commit();

// Install the contract.
let contract_v2_installation_request = ExecuteRequestBuilder::standard(
Expand Down

0 comments on commit 1f72b94

Please sign in to comment.