Rename tokens to lamports in sdk/
This commit is contained in:
@ -574,7 +574,7 @@ mod tests {
|
||||
// ProgramErrors should still be recorded
|
||||
results[0] = Err(BankError::ProgramError(
|
||||
1,
|
||||
ProgramError::ResultWithNegativeTokens,
|
||||
ProgramError::ResultWithNegativeLamports,
|
||||
));
|
||||
BankingStage::record_transactions(&transactions, &results, &poh_recorder).unwrap();
|
||||
let (_, entries) = entry_receiver.recv().unwrap();
|
||||
|
@ -476,7 +476,7 @@ mod tests {
|
||||
entries.push(entry);
|
||||
|
||||
// Add a second Transaction that will produce a
|
||||
// ProgramError<0, ResultWithNegativeTokens> error when processed
|
||||
// ProgramError<0, ResultWithNegativeLamports> error when processed
|
||||
let keypair2 = Keypair::new();
|
||||
let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, blockhash, 0);
|
||||
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
||||
|
@ -32,12 +32,12 @@ impl LeaderConfirmationService {
|
||||
// Hold an accounts_db read lock as briefly as possible, just long enough to collect all
|
||||
// the vote states
|
||||
bank.vote_accounts().for_each(|(_, account)| {
|
||||
total_stake += account.tokens;
|
||||
total_stake += account.lamports;
|
||||
let vote_state = VoteState::deserialize(&account.userdata).unwrap();
|
||||
if let Some(stake_and_state) = vote_state
|
||||
.votes
|
||||
.back()
|
||||
.map(|vote| (vote.slot, account.tokens))
|
||||
.map(|vote| (vote.slot, account.lamports))
|
||||
{
|
||||
slots_and_stakes.push(stake_and_state);
|
||||
}
|
||||
@ -145,7 +145,7 @@ mod tests {
|
||||
let blockhash = bank.last_blockhash();
|
||||
|
||||
// Create a total of 10 vote accounts, each will have a balance of 1 (after giving 1 to
|
||||
// their vote account), for a total staking pool of 10 tokens.
|
||||
// their vote account), for a total staking pool of 10 lamports.
|
||||
let vote_accounts: Vec<_> = (0..10)
|
||||
.map(|i| {
|
||||
// Create new validator to vote
|
||||
@ -153,7 +153,7 @@ mod tests {
|
||||
let voting_keypair = Keypair::new();
|
||||
let voting_pubkey = voting_keypair.pubkey();
|
||||
|
||||
// Give the validator some tokens
|
||||
// Give the validator some lamports
|
||||
bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), blockhash)
|
||||
.unwrap();
|
||||
new_vote_account(&validator_keypair, &voting_pubkey, &bank, 1);
|
||||
|
@ -49,14 +49,17 @@ pub fn num_ticks_left_in_slot(bank: &Bank, tick_height: u64) -> u64 {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::staking_utils;
|
||||
use solana_sdk::genesis_block::{GenesisBlock, BOOTSTRAP_LEADER_TOKENS};
|
||||
use solana_sdk::genesis_block::{GenesisBlock, BOOTSTRAP_LEADER_LAMPORTS};
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
|
||||
#[test]
|
||||
fn test_leader_schedule_via_bank() {
|
||||
let pubkey = Keypair::new().pubkey();
|
||||
let (genesis_block, _mint_keypair) =
|
||||
GenesisBlock::new_with_leader(BOOTSTRAP_LEADER_TOKENS, pubkey, BOOTSTRAP_LEADER_TOKENS);
|
||||
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(
|
||||
BOOTSTRAP_LEADER_LAMPORTS,
|
||||
pubkey,
|
||||
BOOTSTRAP_LEADER_LAMPORTS,
|
||||
);
|
||||
let bank = Bank::new(&genesis_block);
|
||||
|
||||
let ids_and_stakes: Vec<_> = staking_utils::delegated_stakes(&bank).into_iter().collect();
|
||||
@ -72,9 +75,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_leader_scheduler1_basic() {
|
||||
let pubkey = Keypair::new().pubkey();
|
||||
let genesis_block =
|
||||
GenesisBlock::new_with_leader(BOOTSTRAP_LEADER_TOKENS, pubkey, BOOTSTRAP_LEADER_TOKENS)
|
||||
.0;
|
||||
let genesis_block = GenesisBlock::new_with_leader(
|
||||
BOOTSTRAP_LEADER_LAMPORTS,
|
||||
pubkey,
|
||||
BOOTSTRAP_LEADER_LAMPORTS,
|
||||
)
|
||||
.0;
|
||||
let bank = Bank::new(&genesis_block);
|
||||
assert_eq!(slot_leader_at(bank.slot(), &bank), pubkey);
|
||||
}
|
||||
|
@ -292,8 +292,8 @@ impl RpcSol for RpcSolImpl {
|
||||
.get_transaction_count()
|
||||
}
|
||||
|
||||
fn request_airdrop(&self, meta: Self::Metadata, id: String, tokens: u64) -> Result<String> {
|
||||
trace!("request_airdrop id={} tokens={}", id, tokens);
|
||||
fn request_airdrop(&self, meta: Self::Metadata, id: String, lamports: u64) -> Result<String> {
|
||||
trace!("request_airdrop id={} lamports={}", id, lamports);
|
||||
let pubkey = verify_pubkey(id)?;
|
||||
|
||||
let blockhash = meta
|
||||
@ -302,11 +302,13 @@ impl RpcSol for RpcSolImpl {
|
||||
.unwrap()
|
||||
.bank()?
|
||||
.last_blockhash();
|
||||
let transaction = request_airdrop_transaction(&meta.drone_addr, &pubkey, tokens, blockhash)
|
||||
.map_err(|err| {
|
||||
info!("request_airdrop_transaction failed: {:?}", err);
|
||||
Error::internal_error()
|
||||
})?;;
|
||||
let transaction =
|
||||
request_airdrop_transaction(&meta.drone_addr, &pubkey, lamports, blockhash).map_err(
|
||||
|err| {
|
||||
info!("request_airdrop_transaction failed: {:?}", err);
|
||||
Error::internal_error()
|
||||
},
|
||||
)?;;
|
||||
|
||||
let data = serialize(&transaction).map_err(|err| {
|
||||
info!("request_airdrop: serialize error: {:?}", err);
|
||||
@ -517,7 +519,7 @@ mod tests {
|
||||
"jsonrpc":"2.0",
|
||||
"result":{
|
||||
"owner": [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],
|
||||
"tokens": 20,
|
||||
"lamports": 20,
|
||||
"userdata": [],
|
||||
"executable": false
|
||||
},
|
||||
|
@ -106,6 +106,6 @@ pub fn request_airdrop_transaction(
|
||||
let key = Keypair::new();
|
||||
let to = Keypair::new().pubkey();
|
||||
let blockhash = Hash::default();
|
||||
let tx = SystemTransaction::new_account(&key, to, 50, blockhash, 0);
|
||||
let tx = SystemTransaction::new_account(&key, to, lamports, blockhash, 0);
|
||||
Ok(tx)
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ mod tests {
|
||||
"params": {
|
||||
"result": {
|
||||
"owner": budget_program_id,
|
||||
"tokens": 1,
|
||||
"lamports": 1,
|
||||
"userdata": expected_userdata,
|
||||
"executable": executable,
|
||||
|
||||
@ -359,7 +359,7 @@ mod tests {
|
||||
"params": {
|
||||
"result": {
|
||||
"owner": budget_program_id,
|
||||
"tokens": 51,
|
||||
"lamports": 51,
|
||||
"userdata": expected_userdata,
|
||||
"executable": executable,
|
||||
},
|
||||
@ -393,7 +393,7 @@ mod tests {
|
||||
"params": {
|
||||
"result": {
|
||||
"owner": budget_program_id,
|
||||
"tokens": 1,
|
||||
"lamports": 1,
|
||||
"userdata": expected_userdata,
|
||||
"executable": executable,
|
||||
},
|
||||
|
@ -185,7 +185,7 @@ mod tests {
|
||||
subscriptions.check_account(&alice.pubkey(), &account);
|
||||
let string = transport_receiver.poll();
|
||||
if let Async::Ready(Some(response)) = string.unwrap() {
|
||||
let expected = format!(r#"{{"jsonrpc":"2.0","method":"accountNotification","params":{{"result":{{"executable":false,"owner":[129,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],"tokens":1,"userdata":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"subscription":0}}}}"#);
|
||||
let expected = format!(r#"{{"jsonrpc":"2.0","method":"accountNotification","params":{{"result":{{"executable":false,"lamports":1,"owner":[129,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],"userdata":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"subscription":0}}}}"#);
|
||||
assert_eq!(expected, response);
|
||||
}
|
||||
|
||||
|
@ -493,13 +493,13 @@ mod tests {
|
||||
let keypair0 = Keypair::new();
|
||||
let keypair1 = Keypair::new();
|
||||
let keypairs = vec![&keypair0, &keypair1];
|
||||
let tokens = 5;
|
||||
let lamports = 5;
|
||||
let fee = 2;
|
||||
let blockhash = Hash::default();
|
||||
|
||||
let keys = vec![keypair0.pubkey(), keypair1.pubkey()];
|
||||
|
||||
let system_instruction = SystemInstruction::Move { tokens };
|
||||
let system_instruction = SystemInstruction::Move { lamports };
|
||||
|
||||
let program_ids = vec![system_program::id(), solana_budget_api::id()];
|
||||
|
||||
|
@ -121,20 +121,20 @@ impl ThinClient {
|
||||
/// Creates, signs, and processes a Transaction. Useful for writing unit-tests.
|
||||
pub fn transfer(
|
||||
&self,
|
||||
tokens: u64,
|
||||
lamports: u64,
|
||||
keypair: &Keypair,
|
||||
to: Pubkey,
|
||||
blockhash: &Hash,
|
||||
) -> io::Result<Signature> {
|
||||
debug!(
|
||||
"transfer: tokens={} from={:?} to={:?} blockhash={:?}",
|
||||
tokens,
|
||||
"transfer: lamports={} from={:?} to={:?} blockhash={:?}",
|
||||
lamports,
|
||||
keypair.pubkey(),
|
||||
to,
|
||||
blockhash
|
||||
);
|
||||
let now = Instant::now();
|
||||
let transaction = SystemTransaction::new_account(keypair, to, tokens, *blockhash, 0);
|
||||
let transaction = SystemTransaction::new_account(keypair, to, lamports, *blockhash, 0);
|
||||
let result = self.transfer_signed(&transaction);
|
||||
solana_metrics::submit(
|
||||
influxdb::Point::new("thinclient")
|
||||
@ -184,8 +184,8 @@ impl ThinClient {
|
||||
let account: Account =
|
||||
serde_json::from_value(account_json).expect("deserialize account");
|
||||
trace!("Response account {:?} {:?}", pubkey, account);
|
||||
trace!("get_balance {:?}", account.tokens);
|
||||
Ok(account.tokens)
|
||||
trace!("get_balance {:?}", account.lamports);
|
||||
Ok(account.lamports)
|
||||
})
|
||||
.map_err(|error| {
|
||||
debug!("Response account {}: None (error: {:?})", pubkey, error);
|
||||
@ -563,8 +563,8 @@ mod tests {
|
||||
|
||||
let mut tr2 = SystemTransaction::new_account(&alice, bob_pubkey, 501, blockhash, 0);
|
||||
let mut instruction2 = deserialize(tr2.userdata(0)).unwrap();
|
||||
if let SystemInstruction::Move { ref mut tokens } = instruction2 {
|
||||
*tokens = 502;
|
||||
if let SystemInstruction::Move { ref mut lamports } = instruction2 {
|
||||
*lamports = 502;
|
||||
}
|
||||
tr2.instructions[0].userdata = serialize(&instruction2).unwrap();
|
||||
let signature = client.transfer_signed(&tr2).unwrap();
|
||||
@ -587,7 +587,7 @@ mod tests {
|
||||
|
||||
let mut client = mk_client(&leader_data);
|
||||
|
||||
// Create the validator account, transfer some tokens to that account
|
||||
// Create the validator account, transfer some lamports to that account
|
||||
let validator_keypair = Keypair::new();
|
||||
let blockhash = client.get_recent_blockhash();
|
||||
let signature = client
|
||||
@ -660,9 +660,9 @@ mod tests {
|
||||
info!("test_thin_client blockhash: {:?}", blockhash);
|
||||
|
||||
let starting_alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap();
|
||||
info!("Alice has {} tokens", starting_alice_balance);
|
||||
info!("Alice has {} lamports", starting_alice_balance);
|
||||
|
||||
info!("Give Bob 500 tokens");
|
||||
info!("Give Bob 500 lamports");
|
||||
let signature = client
|
||||
.transfer(500, &alice, bob_keypair.pubkey(), &blockhash)
|
||||
.unwrap();
|
||||
@ -671,7 +671,7 @@ mod tests {
|
||||
let bob_balance = client.poll_get_balance(&bob_keypair.pubkey());
|
||||
assert_eq!(bob_balance.unwrap(), 500);
|
||||
|
||||
info!("Take Bob's 500 tokens away");
|
||||
info!("Take Bob's 500 lamports away");
|
||||
let signature = client
|
||||
.transfer(500, &bob_keypair, alice.pubkey(), &blockhash)
|
||||
.unwrap();
|
||||
|
Reference in New Issue
Block a user