From da794b806f522b0917288172f3eae10e2ab4eaa2 Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Wed, 28 Dec 2022 16:50:49 +0100 Subject: [PATCH] Introduces non-null starting balance for faucet transfer --- apps/Cargo.toml | 1 + .../lib/node/ledger/shell/finalize_block.rs | 4 ++-- .../lib/node/ledger/shell/process_proposal.rs | 22 ++++++++++++------- apps/src/lib/node/ledger/shell/queries.rs | 7 +++++- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/apps/Cargo.toml b/apps/Cargo.toml index bd7773e3b3..9c92351033 100644 --- a/apps/Cargo.toml +++ b/apps/Cargo.toml @@ -45,6 +45,7 @@ dev = ["namada/dev"] std = ["ed25519-consensus/std", "rand/std", "rand_core/std"] # for integration tests and test utilies testing = ["dev"] +mainnet = [] abcipp = [ "namada/abcipp", diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index b54f00199a..a5139831a4 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -166,13 +166,13 @@ where ); // Storage read must not fail, but there might // be no value, in which - // case default (0) is returned + // case default (100) is returned balance .expect( "Storage read in the protocol must \ not fail", ) - .unwrap_or_default() + .unwrap_or(Amount::from(100)) } }; diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index 0004db48e5..6d89520afa 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -343,7 +343,8 @@ mod test_process_proposal { } /// Test that if the account submitting the tx is not known and the fee is - /// non-zero, [`process_proposal`] rejects that tx + /// non-zero, [`process_proposal`] rejects that tx. If test is run without [`mainnet`] + /// flag the tx should instead be accepted. #[test] fn test_wrapper_unknown_address() { let (mut shell, _) = TestShell::new(); @@ -354,7 +355,7 @@ mod test_process_proposal { ); let wrapper = WrapperTx::new( Fee { - amount: 1.into(), + amount: 100.into(), token: shell.storage.native_token.clone(), }, &keypair, @@ -377,12 +378,17 @@ mod test_process_proposal { } else { panic!("Test failed") }; - assert_eq!(response.result.code, u32::from(ErrorCodes::InvalidTx)); - assert_eq!( - response.result.info, - "The address given does not have sufficient balance to pay fee" - .to_string(), - ); + #[cfg(feature = "mainnet")] + { + assert_eq!(response.result.code, u32::from(ErrorCodes::InvalidTx)); + assert_eq!( + response.result.info, + "The address given does not have sufficient balance to pay fee" + .to_string(), + ); + } + #[cfg(not(feature = "mainnet"))] + assert_eq!(response.result.code, u32::from(ErrorCodes::Ok)); } /// Test that if the account submitting the tx does diff --git a/apps/src/lib/node/ledger/shell/queries.rs b/apps/src/lib/node/ledger/shell/queries.rs index 77715246ab..760288cd70 100644 --- a/apps/src/lib/node/ledger/shell/queries.rs +++ b/apps/src/lib/node/ledger/shell/queries.rs @@ -77,7 +77,12 @@ where // case default (0) is returned balance .expect("Storage read in the protocol must not fail") - .unwrap_or_default() + .unwrap_or_else(|| { + #[cfg(not(feature = "mainnet"))] + return token::Amount::from(100); + #[cfg(feature = "mainnet")] + return token::Amount::default(); + }) } /// Lookup data about a validator from their protocol signing key