Skip to content

Commit

Permalink
test/e2e: add a test with an account derived from secp256k1 key
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jun 21, 2023
1 parent 8edc06c commit ddf7d35
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
11 changes: 8 additions & 3 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,14 @@ pub fn genesis(num_validators: u64) -> Genesis {
public_key: None,
storage: HashMap::default(),
};
let implicit_accounts = vec![ImplicitAccount {
public_key: wallet::defaults::daewon_keypair().ref_to(),
}];
let implicit_accounts = vec![
ImplicitAccount {
public_key: wallet::defaults::daewon_keypair().ref_to(),
},
ImplicitAccount {
public_key: wallet::defaults::ester_keypair().ref_to(),
},
];
let default_user_tokens = token::Amount::whole(1_000_000);
let default_key_tokens = token::Amount::whole(1_000);
let mut balances: HashMap<Address, token::Amount> = HashMap::from_iter([
Expand Down
24 changes: 22 additions & 2 deletions apps/src/lib/wallet/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#[cfg(any(test, feature = "dev"))]
pub use dev::{
addresses, albert_address, albert_keypair, bertha_address, bertha_keypair,
christel_address, christel_keypair, daewon_address, daewon_keypair, keys,
validator_address, validator_keypair, validator_keys,
christel_address, christel_keypair, daewon_address, daewon_keypair,
ester_address, ester_keypair, keys, validator_address, validator_keypair,
validator_keys,
};
use namada::ledger::wallet::alias::Alias;
use namada::ledger::{eth_bridge, governance, pos};
Expand Down Expand Up @@ -107,6 +108,7 @@ mod dev {
("bertha".into(), bertha_keypair()),
("christel".into(), christel_keypair()),
("daewon".into(), daewon_keypair()),
("ester".into(), ester_keypair()),
("validator".into(), validator_keypair()),
]
}
Expand Down Expand Up @@ -137,6 +139,7 @@ mod dev {
("bertha".into(), bertha_address()),
("christel".into(), christel_address()),
("daewon".into(), daewon_address()),
("ester".into(), ester_address()),
];
let token_addresses = tokens()
.into_iter()
Expand Down Expand Up @@ -166,6 +169,11 @@ mod dev {
(&daewon_keypair().ref_to()).into()
}

/// An implicit user address for testing & development
pub fn ester_address() -> Address {
(&ester_keypair().ref_to()).into()
}

/// An established validator address for testing & development
pub fn validator_address() -> Address {
Address::decode("atest1v4ehgw36ggcnsdee8qerswph8y6ry3p5xgunvve3xaqngd3kxc6nqwz9gseyydzzg5unys3ht2n48q").expect("The token address decoding shouldn't fail")
Expand Down Expand Up @@ -219,6 +227,18 @@ mod dev {
ed_sk.try_to_sk().unwrap()
}

pub fn ester_keypair() -> common::SecretKey {
// generated from
// [`namada::types::key::secp256k1::gen_keypair`]
let bytes = [
54, 144, 147, 226, 3, 93, 132, 247, 42, 126, 90, 23, 200, 155, 122,
147, 139, 93, 8, 204, 135, 178, 40, 152, 5, 227, 175, 204, 102,
239, 154, 66,
];
let sk = secp256k1::SecretKey::try_from_slice(&bytes).unwrap();
sk.try_to_sk().unwrap()
}

pub fn validator_keypair() -> common::SecretKey {
// generated from
// [`namada::types::key::ed25519::gen_keypair`]
Expand Down
9 changes: 9 additions & 0 deletions genesis/e2e-tests-single-node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Bertha = 1000000
Christel = 1000000
"Christel.public_key" = 100
Daewon = 1000000
Ester = 1000000
faucet = 9223372036
"faucet.public_key" = 100
"validator-0.public_key" = 100
Expand All @@ -48,6 +49,7 @@ Albert = 1000000
Bertha = 1000000
Christel = 1000000
Daewon = 1000000
Ester = 1000000
faucet = 9223372036854

[token.ETH]
Expand All @@ -58,6 +60,7 @@ Albert = 1000000
Bertha = 1000000
Christel = 1000000
Daewon = 1000000
Ester = 1000000
faucet = 9223372036854

[token.DOT]
Expand All @@ -68,6 +71,7 @@ Albert = 1000000
Bertha = 1000000
Christel = 1000000
Daewon = 1000000
Ester = 1000000
faucet = 9223372036854

[token.Schnitzel]
Expand All @@ -78,6 +82,7 @@ Albert = 1000000
Bertha = 1000000
Christel = 1000000
Daewon = 1000000
Ester = 1000000
faucet = 9223372036854

[token.Apfel]
Expand All @@ -88,6 +93,7 @@ Albert = 1000000
Bertha = 1000000
Christel = 1000000
Daewon = 1000000
Ester = 1000000
faucet = 9223372036854

[token.Kartoffel]
Expand All @@ -99,6 +105,7 @@ Albert = 1000000
Bertha = 1000000
Christel = 1000000
Daewon = 1000000
Ester = 1000000
faucet = 9223372036854

# Some established accounts present at genesis.
Expand All @@ -120,6 +127,8 @@ vp = "vp_masp"

[implicit.Daewon]

[implicit.Ester]

# Wasm VP definitions

# Implicit VP
Expand Down
22 changes: 21 additions & 1 deletion tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ fn ledger_txs_and_queries() -> Result<()> {
"--node",
&validator_one_rpc,
],
// Submit a token transfer tx (from an implicit account)
// Submit a token transfer tx (from an ed25519 implicit account)
vec![
"transfer",
"--source",
Expand All @@ -425,6 +425,26 @@ fn ledger_txs_and_queries() -> Result<()> {
"--node",
&validator_one_rpc,
],
// Submit a token transfer tx (from a secp256k1 implicit account)
vec![
"transfer",
"--source",
ESTER,
"--target",
ALBERT,
"--token",
NAM,
"--amount",
"10.1",
"--gas-amount",
"0",
"--gas-limit",
"0",
"--gas-token",
NAM,
"--node",
&validator_one_rpc,
],
// 3. Submit a transaction to update an account's validity
// predicate
vec![
Expand Down
1 change: 1 addition & 0 deletions tests/src/e2e/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ pub mod constants {
pub const CHRISTEL: &str = "Christel";
pub const CHRISTEL_KEY: &str = "Christel-key";
pub const DAEWON: &str = "Daewon";
pub const ESTER: &str = "Ester";
pub const MATCHMAKER_KEY: &str = "matchmaker-key";
pub const MASP: &str = "atest1v4ehgw36xaryysfsx5unvve4g5my2vjz89p52sjxxgenzd348yuyyv3hg3pnjs35g5unvde4ca36y5";

Expand Down

0 comments on commit ddf7d35

Please sign in to comment.