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

Condor rc3 #142

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b46d1c7
WIP
deuszex Apr 25, 2024
e2b0b85
WIP
deuszex May 9, 2024
2236196
Commit toolchain for ci/cd
gRoussac May 30, 2024
e1803bb
Disable integer sign extensions (#139)
rafal-ch May 30, 2024
e0eef4e
Disable integer sign extensions (#139)
rafal-ch May 30, 2024
f326785
WIP
deuszex Apr 25, 2024
927de50
2.0.0-rc2
deuszex Jun 17, 2024
a40ad8f
2.0.0-rc2 stable
deuszex Jun 17, 2024
a3557b8
addressing comments, first round of fixture fights
deuszex Jun 20, 2024
5e9fe8c
rc3
deuszex Jun 20, 2024
66e870e
fixture work
deuszex Jun 21, 2024
f2ca245
fixedture
deuszex Jun 21, 2024
2367dca
Small review changes
gRoussac Jun 24, 2024
8c07115
Small rename
gRoussac Jun 25, 2024
d90839e
native eventing (#145)
deuszex Jun 27, 2024
657c088
Merge branch 'condor-rc3' of github.com:casper-ecosystem/cep18 into c…
gRoussac Jul 2, 2024
b7bb5cd
Merge branch 'feat-2.0' of github.com:casper-ecosystem/cep18 into con…
gRoussac Jul 2, 2024
ae334e0
Use DEFAULT_ACCOUNTS in tests (#146)
gRoussac Jul 2, 2024
4cfc946
disallow Key::AddressableEntity::SmartContract in favour of Key::Pack…
deuszex Jul 3, 2024
ccf239a
more event tests
deuszex Jul 3, 2024
a537033
fix fake positive event test
deuszex Jul 3, 2024
06f68a6
remove unused dictinary location check
deuszex Jul 3, 2024
b92a2f5
failing test
deuszex Jul 3, 2024
06325d2
native expansive error topic
deuszex Jul 3, 2024
785a63d
fix allowance migration
deuszex Jul 8, 2024
3243475
fix sec migration
deuszex Jul 8, 2024
13a48b3
removed custom error to see source behind it
deuszex Jul 9, 2024
519d556
fixed migration of contract packages
deuszex Jul 9, 2024
b591ea1
Update utils.rs
deuszex Jul 11, 2024
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ default-members = [
"cep18-test-contract",
"tests",
]
resolver = "2"

[profile.release]
codegen-units = 1
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PINNED_TOOLCHAIN := $(shell cat rust-toolchain)
PINNED_TOOLCHAIN := $(shell cat cep18/rust-toolchain)

prepare:
rustup target add wasm32-unknown-unknown
Expand All @@ -18,14 +18,22 @@ setup-test: build-contract
cp ./target/wasm32-unknown-unknown/release/cep18.wasm tests/wasm
cp ./target/wasm32-unknown-unknown/release/cep18_test_contract.wasm tests/wasm

native-test: setup-test
cd tests && cargo test --lib should_transfer_account_to_account

test: setup-test
cd tests && cargo test
cd tests && cargo test --lib

clippy:
cd cep18 && cargo clippy --all-targets -- -D warnings
cd cep18-test-contract && cargo clippy --all-targets -- -D warnings
cd tests && cargo clippy --all-targets -- -D warnings

format:
cd cep18 && cargo fmt
cd cep18-test-contract && cargo fmt
cd tests && cargo fmt

check-lint: clippy
cd cep18 && cargo fmt -- --check
cd cep18-test-contract && cargo fmt -- --check
Expand Down
9 changes: 4 additions & 5 deletions cep18-test-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[package]
name = "cep18-test-contract"
version = "1.2.0"
authors = ["Michał Papierski <michal@casperlabs.io>"]
edition = "2018"
version = "2.0.0"
edition = "2021"

[[bin]]
name = "cep18_test_contract"
Expand All @@ -12,5 +11,5 @@ doctest = false
test = false

[dependencies]
casper-contract = "3.0.0"
casper-types = "3.0.0"
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc3"}
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc3"}
1 change: 1 addition & 0 deletions cep18-test-contract/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2024-05-28
2 changes: 1 addition & 1 deletion rustfmt.toml → cep18-test-contract/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wrap_comments = true
comment_width = 100
imports_granularity = "Crate"
edition = "2018"
edition = "2021"
92 changes: 54 additions & 38 deletions cep18-test-contract/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use casper_contract::{
};

use casper_types::{
bytesrepr::ToBytes, runtime_args, CLTyped, ContractHash, EntryPoint, EntryPointAccess,
EntryPointType, EntryPoints, Key, Parameter, RuntimeArgs, U256,
bytesrepr::ToBytes, runtime_args, AddressableEntityHash, ApiError, CLTyped, EntryPoint,
EntryPointAccess, EntryPointType, EntryPoints, Key, Parameter, RuntimeArgs, U256,
};

const CHECK_TOTAL_SUPPLY_ENTRY_POINT_NAME: &str = "check_total_supply";
Expand Down Expand Up @@ -54,11 +54,10 @@ fn store_result<T: CLTyped + ToBytes>(result: T) {

#[no_mangle]
extern "C" fn check_total_supply() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert_with(ApiError::User(61000));
let total_supply: U256 = runtime::call_contract(
token_contract,
TOTAL_SUPPLY_ENTRY_POINT_NAME,
Expand All @@ -69,11 +68,10 @@ extern "C" fn check_total_supply() {

#[no_mangle]
extern "C" fn check_balance_of() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert_with(ApiError::User(61001));
let address: Key = runtime::get_named_arg(ADDRESS_RUNTIME_ARG_NAME);

let balance_args = runtime_args! {
Expand All @@ -87,11 +85,10 @@ extern "C" fn check_balance_of() {

#[no_mangle]
extern "C" fn check_allowance_of() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert_with(ApiError::User(61002));
let owner: Key = runtime::get_named_arg(OWNER_RUNTIME_ARG_NAME);
let spender: Key = runtime::get_named_arg(SPENDER_RUNTIME_ARG_NAME);

Expand All @@ -107,11 +104,10 @@ extern "C" fn check_allowance_of() {

#[no_mangle]
extern "C" fn transfer_as_stored_contract() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert_with(ApiError::User(61003));
let recipient: Key = runtime::get_named_arg(RECIPIENT_RUNTIME_ARG_NAME);
let amount: U256 = runtime::get_named_arg(AMOUNT_RUNTIME_ARG_NAME);

Expand All @@ -125,11 +121,10 @@ extern "C" fn transfer_as_stored_contract() {

#[no_mangle]
extern "C" fn transfer_from_as_stored_contract() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert_with(ApiError::User(61004));
let owner: Key = runtime::get_named_arg(OWNER_RUNTIME_ARG_NAME);
let recipient: Key = runtime::get_named_arg(RECIPIENT_RUNTIME_ARG_NAME);
let amount: U256 = runtime::get_named_arg(AMOUNT_RUNTIME_ARG_NAME);
Expand All @@ -149,11 +144,10 @@ extern "C" fn transfer_from_as_stored_contract() {

#[no_mangle]
extern "C" fn approve_as_stored_contract() {
let token_contract: ContractHash = ContractHash::new(
let token_contract: AddressableEntityHash =
runtime::get_named_arg::<Key>(TOKEN_CONTRACT_RUNTIME_ARG_NAME)
.into_hash()
.unwrap_or_revert(),
);
.into_entity_hash()
.unwrap_or_revert_with(ApiError::User(61005));
let spender: Key = runtime::get_named_arg(SPENDER_RUNTIME_ARG_NAME);
let amount: U256 = runtime::get_named_arg(AMOUNT_RUNTIME_ARG_NAME);

Expand All @@ -172,69 +166,90 @@ pub extern "C" fn call() {
String::from(CHECK_TOTAL_SUPPLY_ENTRY_POINT_NAME),
vec![Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
ContractHash::cl_type(),
AddressableEntityHash::cl_type(),
)],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
casper_types::EntryPointPayment::Caller,
);
let check_balance_of_entrypoint = EntryPoint::new(
String::from(CHECK_BALANCE_OF_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(ADDRESS_RUNTIME_ARG_NAME, Key::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
casper_types::EntryPointPayment::Caller,
);
let check_allowance_of_entrypoint = EntryPoint::new(
String::from(CHECK_ALLOWANCE_OF_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(OWNER_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(SPENDER_RUNTIME_ARG_NAME, Key::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
casper_types::EntryPointPayment::Caller,
);

let transfer_as_stored_contract_entrypoint = EntryPoint::new(
String::from(TRANSFER_AS_STORED_CONTRACT_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(RECIPIENT_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(AMOUNT_RUNTIME_ARG_NAME, U256::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
casper_types::EntryPointPayment::Caller,
);

let approve_as_stored_contract_entrypoint = EntryPoint::new(
String::from(APPROVE_AS_STORED_CONTRACT_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(SPENDER_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(AMOUNT_RUNTIME_ARG_NAME, U256::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
casper_types::EntryPointPayment::Caller,
);

let transfer_from_as_stored_contract_entrypoint = EntryPoint::new(
String::from(TRANSFER_FROM_AS_STORED_CONTRACT_ENTRY_POINT_NAME),
vec![
Parameter::new(TOKEN_CONTRACT_RUNTIME_ARG_NAME, ContractHash::cl_type()),
Parameter::new(
TOKEN_CONTRACT_RUNTIME_ARG_NAME,
AddressableEntityHash::cl_type(),
),
Parameter::new(OWNER_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(RECIPIENT_RUNTIME_ARG_NAME, Key::cl_type()),
Parameter::new(AMOUNT_RUNTIME_ARG_NAME, U256::cl_type()),
],
<()>::cl_type(),
EntryPointAccess::Public,
EntryPointType::Contract,
EntryPointType::Called,
casper_types::EntryPointPayment::Caller,
);

entry_points.add_entry_point(check_total_supply_entrypoint);
Expand All @@ -249,5 +264,6 @@ pub extern "C" fn call() {
None,
Some(CEP18_TEST_CALL_KEY.to_string()),
None,
None,
);
}
10 changes: 5 additions & 5 deletions cep18/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cep18"
version = "1.2.0"
edition = "2018"
version = "2.0.0"
edition = "2021"
description = "A library for developing CEP-18 tokens for the Casper network."
readme = "README.md"
documentation = "https://docs.rs/casper-cep18"
Expand All @@ -18,8 +18,8 @@ test = false

[dependencies]
base64 = { version = "0.20.0", default-features = false, features = ["alloc"] }
casper-contract = "3.0.0"
casper-types = "3.0.0"
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc3"}
casper-contract = { git = "https://github.com/casper-network/casper-node.git", branch = "release-2.0.0-rc3"}
hex = { version = "0.4.3", default-features = false }
once_cell = { version = "1.16.0", default-features = false }
casper-event-standard = { version = "0.4.1", default-features = false }
casper-event-standard = { git = "https://github.com/deuszex/casper-event-standard", branch = "condor", default-features = false }
1 change: 1 addition & 0 deletions cep18/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2024-05-28
4 changes: 4 additions & 0 deletions cep18/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wrap_comments = true
comment_width = 100
imports_granularity = "Crate"
edition = "2021"
16 changes: 12 additions & 4 deletions cep18/src/allowances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use casper_contract::{
};
use casper_types::{bytesrepr::ToBytes, Key, URef, U256};

use crate::{constants::ALLOWANCES, utils};
use crate::{constants::ALLOWANCES, utils, Cep18Error};

#[inline]
pub(crate) fn get_allowances_uref() -> URef {
Expand All @@ -17,8 +17,16 @@ pub(crate) fn get_allowances_uref() -> URef {
/// Creates a dictionary item key for an (owner, spender) pair.
pub(crate) fn make_dictionary_item_key(owner: Key, spender: Key) -> String {
let mut preimage = Vec::new();
preimage.append(&mut owner.to_bytes().unwrap_or_revert());
preimage.append(&mut spender.to_bytes().unwrap_or_revert());
preimage.append(
&mut owner
.to_bytes()
.unwrap_or_revert_with(Cep18Error::FailedToConvertBytes),
);
preimage.append(
&mut spender
.to_bytes()
.unwrap_or_revert_with(Cep18Error::FailedToConvertBytes),
);

let key_bytes = runtime::blake2b(&preimage);
hex::encode(key_bytes)
Expand All @@ -34,6 +42,6 @@ pub(crate) fn write_allowance_to(allowance_uref: URef, owner: Key, spender: Key,
pub(crate) fn read_allowance_from(allowances_uref: URef, owner: Key, spender: Key) -> U256 {
let dictionary_item_key = make_dictionary_item_key(owner, spender);
storage::dictionary_get(allowances_uref, &dictionary_item_key)
.unwrap_or_revert()
.unwrap_or_revert_with(Cep18Error::FailedToGetDictionaryValue)
.unwrap_or_default()
}
6 changes: 4 additions & 2 deletions cep18/src/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use crate::{constants::BALANCES, error::Cep18Error, utils};
/// since stringified Keys are too long to be used as dictionary keys.
#[inline]
fn make_dictionary_item_key(owner: Key) -> String {
let preimage = owner.to_bytes().unwrap_or_revert();
let preimage = owner
.to_bytes()
.unwrap_or_revert_with(Cep18Error::FailedToConvertBytes);
// NOTE: As for now dictionary item keys are limited to 64 characters only. Instead of using
// hashing (which will effectively hash a hash) we'll use base64. Preimage is 33 bytes for
// both used Key variants, and approximated base64-encoded length will be 4 * (33 / 3) ~ 44
Expand Down Expand Up @@ -38,7 +40,7 @@ pub(crate) fn read_balance_from(balances_uref: URef, address: Key) -> U256 {
let dictionary_item_key = make_dictionary_item_key(address);

storage::dictionary_get(balances_uref, &dictionary_item_key)
.unwrap_or_revert()
.unwrap_or_revert_with(Cep18Error::FailedToGetDictionaryValue)
.unwrap_or_default()
}

Expand Down
12 changes: 10 additions & 2 deletions cep18/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub const BALANCES: &str = "balances";
pub const ALLOWANCES: &str = "allowances";
/// Name of named-key for `total_supply`
pub const TOTAL_SUPPLY: &str = "total_supply";
pub const EVENTS: &str = "events";
pub const REVERT: &str = "revert";
pub const ERRORS: &str = "errors";
pub const CONDOR: &str = "condor";

pub const HASH_KEY_NAME_PREFIX: &str = "cep18_contract_package_";
pub const ACCESS_KEY_NAME_PREFIX: &str = "cep18_contract_package_access_";
Expand Down Expand Up @@ -44,6 +48,10 @@ pub const BURN_ENTRY_POINT_NAME: &str = "burn";
pub const INIT_ENTRY_POINT_NAME: &str = "init";
/// Name of `change_security` entry point.
pub const CHANGE_SECURITY_ENTRY_POINT_NAME: &str = "change_security";
pub const MIGRATE_USER_BALANCE_KEYS_ENTRY_POINT_NAME: &str = "migrate_user_balance_keys";
pub const MIGRATE_USER_ALLOWANCE_KEYS_ENTRY_POINT_NAME: &str = "migrate_user_allowance_keys";
pub const MIGRATE_USER_SEC_KEYS_ENTRY_POINT_NAME: &str = "migrate_sec_keys";
pub const CHANGE_EVENTS_MODE_ENTRY_POINT_NAME: &str = "change_events_mode";

pub const INCREASE_ALLOWANCE_ENTRY_POINT_NAME: &str = "increase_allowance";
pub const DECREASE_ALLOWANCE_ENTRY_POINT_NAME: &str = "decrease_allowance";
Expand All @@ -59,11 +67,11 @@ pub const AMOUNT: &str = "amount";
/// Name of `recipient` runtime argument.
pub const RECIPIENT: &str = "recipient";
pub const PACKAGE_HASH: &str = "package_hash";
pub const CONTRACT_HASH: &str = "contract_hash";
pub const EVENTS_MODE: &str = "events_mode";
pub const SECURITY_BADGES: &str = "security_badges";
pub const ADMIN_LIST: &str = "admin_list";
pub const MINTER_LIST: &str = "minter_list";
pub const BURNER_LIST: &str = "burner_list";
pub const NONE_LIST: &str = "none_list";
pub const MINT_AND_BURN_LIST: &str = "mint_and_burn_list";
pub const ENABLE_MINT_BURN: &str = "enable_mint_burn";
pub const USER_KEY_MAP: &str = "user_key_map";
Loading