forked from casper-network/casper-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathee_598.rs
More file actions
95 lines (82 loc) · 3.26 KB
/
ee_598.rs
File metadata and controls
95 lines (82 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use num_traits::Zero;
use once_cell::sync::Lazy;
use casper_engine_test_support::{
utils, DeployItemBuilder, ExecuteRequestBuilder, LmdbWasmTestBuilder, DEFAULT_ACCOUNTS,
DEFAULT_ACCOUNT_ADDR,
};
use casper_types::{
account::AccountHash, runtime_args, system::auction::DelegationRate, GenesisAccount,
GenesisValidator, Motes, PublicKey, SecretKey, U512,
};
const ARG_AMOUNT: &str = "amount";
const ARG_PUBLIC_KEY: &str = "public_key";
const ARG_ENTRY_POINT: &str = "entry_point";
const ARG_ACCOUNT_HASH: &str = "account_hash";
const CONTRACT_AUCTION_BIDDING: &str = "auction_bidding.wasm";
static ACCOUNT_1_PK: Lazy<PublicKey> = Lazy::new(|| {
let secret_key = SecretKey::ed25519_from_bytes([4; SecretKey::ED25519_LENGTH]).unwrap();
PublicKey::from(&secret_key)
});
const GENESIS_VALIDATOR_STAKE: u64 = 50_000;
static ACCOUNT_1_ADDR: Lazy<AccountHash> = Lazy::new(|| AccountHash::from(&*ACCOUNT_1_PK));
static ACCOUNT_1_FUND: Lazy<U512> = Lazy::new(|| U512::from(10_000_000_000_000u64));
static ACCOUNT_1_BALANCE: Lazy<U512> = Lazy::new(|| *ACCOUNT_1_FUND + 100_000);
static ACCOUNT_1_BOND: Lazy<U512> = Lazy::new(|| U512::from(25_000));
#[ignore]
#[test]
fn should_handle_unbond_for_more_than_stake_as_full_unbond_of_stake_ee_598_regression() {
let secret_key = SecretKey::ed25519_from_bytes([42; SecretKey::ED25519_LENGTH]).unwrap();
let public_key = PublicKey::from(&secret_key);
let accounts = {
let mut tmp: Vec<GenesisAccount> = DEFAULT_ACCOUNTS.clone();
let account = GenesisAccount::account(
public_key,
Motes::new(GENESIS_VALIDATOR_STAKE)
.checked_mul(Motes::new(2))
.unwrap(),
Some(GenesisValidator::new(
Motes::new(GENESIS_VALIDATOR_STAKE),
DelegationRate::zero(),
)),
);
tmp.push(account);
tmp
};
let run_genesis_request = utils::create_run_genesis_request(accounts);
let seed_request = ExecuteRequestBuilder::standard(
*DEFAULT_ACCOUNT_ADDR,
CONTRACT_AUCTION_BIDDING,
runtime_args! {
ARG_ENTRY_POINT => "seed_new_account",
ARG_ACCOUNT_HASH => *ACCOUNT_1_ADDR,
ARG_AMOUNT => *ACCOUNT_1_BALANCE,
},
)
.build();
let deploy = DeployItemBuilder::new()
.with_address(*ACCOUNT_1_ADDR)
.with_standard_payment(runtime_args! { ARG_AMOUNT => *ACCOUNT_1_FUND })
.with_session_code(
"ee_598_regression.wasm",
runtime_args! {
ARG_AMOUNT => *ACCOUNT_1_BOND,
ARG_PUBLIC_KEY => ACCOUNT_1_PK.clone(),
},
)
.with_deploy_hash([2u8; 32])
.with_authorization_keys(&[*ACCOUNT_1_ADDR])
.build();
let combined_bond_and_unbond_request = ExecuteRequestBuilder::from_deploy_item(&deploy).build();
let mut builder = LmdbWasmTestBuilder::default();
builder.run_genesis(run_genesis_request);
builder.exec(seed_request).expect_success().commit();
builder
.exec(combined_bond_and_unbond_request)
.expect_failure()
.commit();
let err = builder.get_error().expect("should have error");
assert_eq!(
"ApiError::AuctionError(UnbondTooLarge) [64532]",
err.to_string()
);
}