-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: igor-casper <[email protected]>
- Loading branch information
1 parent
5120537
commit 63ef365
Showing
17 changed files
with
474 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
216 changes: 216 additions & 0 deletions
216
execution_engine_testing/tests/src/test/system_contracts/mint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
use casper_engine_test_support::{ | ||
auction, ExecuteRequestBuilder, LmdbWasmTestBuilder, DEFAULT_ACCOUNT_ADDR, | ||
}; | ||
use casper_types::{runtime_args, ProtocolVersion, RuntimeArgs, URef, U512}; | ||
|
||
use tempfile::TempDir; | ||
|
||
const TEST_DELEGATOR_INITIAL_ACCOUNT_BALANCE: u64 = 1_000_000 * 1_000_000_000; | ||
|
||
const CONTRACT_BURN: &str = "burn.wasm"; | ||
const CONTRACT_TRANSFER_TO_NAMED_PURSE: &str = "transfer_to_named_purse.wasm"; | ||
|
||
const ARG_AMOUNT: &str = "amount"; | ||
|
||
const ARG_PURSE_NAME: &str = "purse_name"; | ||
|
||
#[ignore] | ||
#[test] | ||
fn should_empty_purse_when_burning_above_balance() { | ||
let data_dir = TempDir::new().expect("should create temp dir"); | ||
let mut builder = LmdbWasmTestBuilder::new(data_dir.as_ref()); | ||
let source = *DEFAULT_ACCOUNT_ADDR; | ||
|
||
let delegator_keys = auction::generate_public_keys(1); | ||
let validator_keys = auction::generate_public_keys(1); | ||
|
||
auction::run_genesis_and_create_initial_accounts( | ||
&mut builder, | ||
&validator_keys, | ||
delegator_keys | ||
.iter() | ||
.map(|public_key| public_key.to_account_hash()) | ||
.collect::<Vec<_>>(), | ||
U512::from(TEST_DELEGATOR_INITIAL_ACCOUNT_BALANCE), | ||
); | ||
|
||
let initial_supply = builder.total_supply(None); | ||
let purse_name = "purse"; | ||
let purse_amount = U512::from(10_000_000_000u64); | ||
|
||
// Create purse and transfer tokens to it | ||
let exec_request = ExecuteRequestBuilder::standard( | ||
source, | ||
CONTRACT_TRANSFER_TO_NAMED_PURSE, | ||
runtime_args! { | ||
ARG_PURSE_NAME => purse_name, | ||
ARG_AMOUNT => purse_amount, | ||
}, | ||
) | ||
.build(); | ||
|
||
builder.exec(exec_request).expect_success().commit(); | ||
|
||
let account = builder | ||
.get_entity_with_named_keys_by_account_hash(source) | ||
.expect("should have account"); | ||
|
||
let purse_uref: URef = account | ||
.named_keys() | ||
.get(purse_name) | ||
.unwrap() | ||
.into_uref() | ||
.expect("should be uref"); | ||
|
||
assert_eq!( | ||
builder | ||
.get_purse_balance_result(ProtocolVersion::V2_0_0, purse_uref) | ||
.motes() | ||
.cloned() | ||
.unwrap(), | ||
purse_amount | ||
); | ||
|
||
// Burn part of tokens in a purse | ||
let num_of_tokens_to_burn = U512::from(2_000_000_000u64); | ||
let num_of_tokens_after_burn = U512::from(8_000_000_000u64); | ||
|
||
let exec_request = ExecuteRequestBuilder::standard( | ||
source, | ||
CONTRACT_BURN, | ||
runtime_args! { | ||
ARG_PURSE_NAME => purse_name, | ||
ARG_AMOUNT => num_of_tokens_to_burn, | ||
}, | ||
) | ||
.build(); | ||
|
||
builder.exec(exec_request).expect_success().commit(); | ||
|
||
assert_eq!( | ||
builder | ||
.get_purse_balance_result(ProtocolVersion::V2_0_0, purse_uref) | ||
.motes() | ||
.cloned() | ||
.unwrap(), | ||
num_of_tokens_after_burn | ||
); | ||
|
||
// Burn rest of tokens in a purse | ||
let num_of_tokens_to_burn = U512::from(8_000_000_000u64); | ||
let num_of_tokens_after_burn = U512::zero(); | ||
|
||
let exec_request = ExecuteRequestBuilder::standard( | ||
source, | ||
CONTRACT_BURN, | ||
runtime_args! { | ||
ARG_PURSE_NAME => purse_name, | ||
ARG_AMOUNT => num_of_tokens_to_burn, | ||
}, | ||
) | ||
.build(); | ||
|
||
builder.exec(exec_request).expect_success().commit(); | ||
|
||
assert_eq!( | ||
builder | ||
.get_purse_balance_result(ProtocolVersion::V2_0_0, purse_uref) | ||
.motes() | ||
.cloned() | ||
.unwrap(), | ||
num_of_tokens_after_burn | ||
); | ||
|
||
let supply_after_burns = builder.total_supply(None); | ||
let expected_supply_after_burns = initial_supply - U512::from(10_000_000_000u64); | ||
|
||
assert_eq!(supply_after_burns, expected_supply_after_burns); | ||
} | ||
|
||
#[ignore] | ||
#[test] | ||
fn should_not_burn_excess_tokens() { | ||
let data_dir = TempDir::new().expect("should create temp dir"); | ||
let mut builder = LmdbWasmTestBuilder::new(data_dir.as_ref()); | ||
let source = *DEFAULT_ACCOUNT_ADDR; | ||
|
||
let delegator_keys = auction::generate_public_keys(1); | ||
let validator_keys = auction::generate_public_keys(1); | ||
|
||
auction::run_genesis_and_create_initial_accounts( | ||
&mut builder, | ||
&validator_keys, | ||
delegator_keys | ||
.iter() | ||
.map(|public_key| public_key.to_account_hash()) | ||
.collect::<Vec<_>>(), | ||
U512::from(TEST_DELEGATOR_INITIAL_ACCOUNT_BALANCE), | ||
); | ||
|
||
let initial_supply = builder.total_supply(None); | ||
let purse_name = "purse"; | ||
let purse_amount = U512::from(10_000_000_000u64); | ||
|
||
// Create purse and transfer tokens to it | ||
let exec_request = ExecuteRequestBuilder::standard( | ||
source, | ||
CONTRACT_TRANSFER_TO_NAMED_PURSE, | ||
runtime_args! { | ||
ARG_PURSE_NAME => purse_name, | ||
ARG_AMOUNT => purse_amount, | ||
}, | ||
) | ||
.build(); | ||
|
||
builder.exec(exec_request).expect_success().commit(); | ||
|
||
let account = builder | ||
.get_entity_with_named_keys_by_account_hash(source) | ||
.expect("should have account"); | ||
|
||
let purse_uref: URef = account | ||
.named_keys() | ||
.get(purse_name) | ||
.unwrap() | ||
.into_uref() | ||
.expect("should be uref"); | ||
|
||
assert_eq!( | ||
builder | ||
.get_purse_balance_result(ProtocolVersion::V2_0_0, purse_uref) | ||
.motes() | ||
.cloned() | ||
.unwrap(), | ||
purse_amount | ||
); | ||
|
||
// Try to burn more then in a purse | ||
let num_of_tokens_to_burn = U512::MAX; | ||
let num_of_tokens_after_burn = U512::zero(); | ||
|
||
let exec_request = ExecuteRequestBuilder::standard( | ||
source, | ||
CONTRACT_BURN, | ||
runtime_args! { | ||
ARG_PURSE_NAME => purse_name, | ||
ARG_AMOUNT => num_of_tokens_to_burn, | ||
}, | ||
) | ||
.build(); | ||
|
||
builder.exec(exec_request).expect_success().commit(); | ||
|
||
assert_eq!( | ||
builder | ||
.get_purse_balance_result(ProtocolVersion::V2_0_0, purse_uref) | ||
.motes() | ||
.cloned() | ||
.unwrap(), | ||
num_of_tokens_after_burn, | ||
); | ||
|
||
let supply_after_burns = builder.total_supply(None); | ||
let expected_supply_after_burns = initial_supply - U512::from(10_000_000_000u64); | ||
|
||
assert_eq!(supply_after_burns, expected_supply_after_burns); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ mod auction; | |
mod auction_bidding; | ||
mod genesis; | ||
mod handle_payment; | ||
mod mint; | ||
mod standard_payment; | ||
mod upgrade; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "burn" | ||
version = "0.1.0" | ||
authors = ["Igor Bunar <[email protected]>", "Jan Hoffmann <[email protected]>"] | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "burn" | ||
path = "src/main.rs" | ||
bench = false | ||
doctest = false | ||
test = false | ||
|
||
[dependencies] | ||
casper-contract = { path = "../../../contract" } | ||
casper-types = { path = "../../../../types" } |
Oops, something went wrong.