Require a self-assigned account ID
This commit is contained in:
parent
8ccfb26923
commit
0172422961
|
@ -16,7 +16,7 @@ pub enum SystemContract {
|
||||||
CreateAccount {
|
CreateAccount {
|
||||||
tokens: i64,
|
tokens: i64,
|
||||||
space: u64,
|
space: u64,
|
||||||
contract_id: Option<Pubkey>,
|
contract_id: Pubkey,
|
||||||
},
|
},
|
||||||
/// Assign account to a contract
|
/// Assign account to a contract
|
||||||
/// * Transaction::keys[0] - account to assign
|
/// * Transaction::keys[0] - account to assign
|
||||||
|
@ -59,9 +59,7 @@ impl SystemContract {
|
||||||
}
|
}
|
||||||
accounts[0].tokens -= tokens;
|
accounts[0].tokens -= tokens;
|
||||||
accounts[1].tokens += tokens;
|
accounts[1].tokens += tokens;
|
||||||
if let Some(id) = contract_id {
|
accounts[1].contract_id = contract_id;
|
||||||
accounts[1].contract_id = id;
|
|
||||||
}
|
|
||||||
accounts[1].userdata = vec![0; space as usize];
|
accounts[1].userdata = vec![0; space as usize];
|
||||||
}
|
}
|
||||||
SystemContract::Assign { contract_id } => {
|
SystemContract::Assign { contract_id } => {
|
||||||
|
@ -123,15 +121,8 @@ mod test {
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let mut accounts = vec![Account::default(), Account::default()];
|
let mut accounts = vec![Account::default(), Account::default()];
|
||||||
let tx = Transaction::system_create(
|
let tx =
|
||||||
&from,
|
Transaction::system_create(&from, to.pubkey(), Hash::default(), 0, 1, to.pubkey(), 0);
|
||||||
to.pubkey(),
|
|
||||||
Hash::default(),
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
Some(to.pubkey()),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
SystemContract::process_transaction(&tx, &mut accounts);
|
SystemContract::process_transaction(&tx, &mut accounts);
|
||||||
assert!(accounts[0].userdata.is_empty());
|
assert!(accounts[0].userdata.is_empty());
|
||||||
assert_eq!(accounts[1].userdata.len(), 1);
|
assert_eq!(accounts[1].userdata.len(), 1);
|
||||||
|
@ -143,7 +134,15 @@ mod test {
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let mut accounts = vec![Account::default(), Account::default()];
|
let mut accounts = vec![Account::default(), Account::default()];
|
||||||
accounts[1].contract_id = to.pubkey();
|
accounts[1].contract_id = to.pubkey();
|
||||||
let tx = Transaction::system_create(&from, to.pubkey(), Hash::default(), 0, 1, None, 0);
|
let tx = Transaction::system_create(
|
||||||
|
&from,
|
||||||
|
to.pubkey(),
|
||||||
|
Hash::default(),
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
Pubkey::default(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
SystemContract::process_transaction(&tx, &mut accounts);
|
SystemContract::process_transaction(&tx, &mut accounts);
|
||||||
assert!(accounts[1].userdata.is_empty());
|
assert!(accounts[1].userdata.is_empty());
|
||||||
}
|
}
|
||||||
|
@ -153,7 +152,15 @@ mod test {
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let mut accounts = vec![Account::default(), Account::default()];
|
let mut accounts = vec![Account::default(), Account::default()];
|
||||||
accounts[0].contract_id = to.pubkey();
|
accounts[0].contract_id = to.pubkey();
|
||||||
let tx = Transaction::system_create(&from, to.pubkey(), Hash::default(), 0, 1, None, 0);
|
let tx = Transaction::system_create(
|
||||||
|
&from,
|
||||||
|
to.pubkey(),
|
||||||
|
Hash::default(),
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
Pubkey::default(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
SystemContract::process_transaction(&tx, &mut accounts);
|
SystemContract::process_transaction(&tx, &mut accounts);
|
||||||
assert!(accounts[1].userdata.is_empty());
|
assert!(accounts[1].userdata.is_empty());
|
||||||
}
|
}
|
||||||
|
@ -163,7 +170,15 @@ mod test {
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let mut accounts = vec![Account::default(), Account::default()];
|
let mut accounts = vec![Account::default(), Account::default()];
|
||||||
accounts[1].userdata = vec![0, 0, 0];
|
accounts[1].userdata = vec![0, 0, 0];
|
||||||
let tx = Transaction::system_create(&from, to.pubkey(), Hash::default(), 0, 2, None, 0);
|
let tx = Transaction::system_create(
|
||||||
|
&from,
|
||||||
|
to.pubkey(),
|
||||||
|
Hash::default(),
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
Pubkey::default(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
SystemContract::process_transaction(&tx, &mut accounts);
|
SystemContract::process_transaction(&tx, &mut accounts);
|
||||||
assert_eq!(accounts[1].userdata.len(), 3);
|
assert_eq!(accounts[1].userdata.len(), 3);
|
||||||
}
|
}
|
||||||
|
@ -202,15 +217,15 @@ mod test {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
111,
|
111,
|
||||||
222,
|
222,
|
||||||
Some(Pubkey::new(&BUDGET_CONTRACT_ID)),
|
Pubkey::new(&BUDGET_CONTRACT_ID),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tx.userdata,
|
tx.userdata,
|
||||||
vec![
|
vec![
|
||||||
0, 0, 0, 0, 111, 0, 0, 0, 0, 0, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
|
0, 0, 0, 0, 111, 0, 0, 0, 0, 0, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -221,13 +236,16 @@ mod test {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
111,
|
111,
|
||||||
222,
|
222,
|
||||||
None,
|
Pubkey::default(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tx.userdata,
|
tx.userdata,
|
||||||
vec![0, 0, 0, 0, 111, 0, 0, 0, 0, 0, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 0]
|
vec![
|
||||||
|
0, 0, 0, 0, 111, 0, 0, 0, 0, 0, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Assign
|
// Assign
|
||||||
|
|
|
@ -187,7 +187,7 @@ impl Transaction {
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
tokens: i64,
|
tokens: i64,
|
||||||
space: u64,
|
space: u64,
|
||||||
contract_id: Option<Pubkey>,
|
contract_id: Pubkey,
|
||||||
fee: i64,
|
fee: i64,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let create = SystemContract::CreateAccount {
|
let create = SystemContract::CreateAccount {
|
||||||
|
@ -223,7 +223,7 @@ impl Transaction {
|
||||||
}
|
}
|
||||||
/// Create and sign new SystemContract::CreateAccount transaction with some defaults
|
/// Create and sign new SystemContract::CreateAccount transaction with some defaults
|
||||||
pub fn system_new(from_keypair: &Keypair, to: Pubkey, tokens: i64, last_id: Hash) -> Self {
|
pub fn system_new(from_keypair: &Keypair, to: Pubkey, tokens: i64, last_id: Hash) -> Self {
|
||||||
Transaction::system_create(from_keypair, to, last_id, tokens, 0, None, 0)
|
Transaction::system_create(from_keypair, to, last_id, tokens, 0, Pubkey::default(), 0)
|
||||||
}
|
}
|
||||||
/// Create and sign new SystemContract::Move transaction
|
/// Create and sign new SystemContract::Move transaction
|
||||||
pub fn system_move(
|
pub fn system_move(
|
||||||
|
|
Loading…
Reference in New Issue