Skip to content

Commit

Permalink
[fix]: Fix failing test-wasm by adding code section and also signing …
Browse files Browse the repository at this point in the history
…over that.
  • Loading branch information
murisi committed Jul 2, 2023
1 parent a3a8bbc commit d52a137
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
20 changes: 12 additions & 8 deletions wasm/wasm_source/src/vp_implicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -605,8 +606,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -760,7 +762,8 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash()], &secret_key)));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash(), *tx.code_sechash()], &secret_key)));
let signed_tx = tx.clone();
vp_env.tx = signed_tx.clone();
let keys_changed: BTreeSet<storage::Key> =
Expand Down Expand Up @@ -846,8 +849,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -875,8 +879,8 @@ mod tests {
// for the update
tx_env.store_wasm_code(vp_code);

// hardcoded hash of VP_ALWAYS_TRUE_WASM
tx_env.init_parameters(None, None, Some(vec![vp_hash.to_string()]));
let empty_sha256 = sha256(&[]).to_string();
tx_env.init_parameters(None, None, Some(vec![empty_sha256]));

// Spawn the accounts to be able to modify their storage
tx_env.spawn_accounts([&vp_owner]);
Expand All @@ -893,10 +897,10 @@ mod tests {

let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_code(Code::from_hash(vp_hash));
tx.set_code(Code::new(vec![]));
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down
11 changes: 7 additions & 4 deletions wasm/wasm_source/src/vp_testnet_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn validate_tx(
#[cfg(test)]
mod tests {
use address::testing::arb_non_internal_address;
use namada::proto::{Data, Signature};
use namada::proto::{Code, Data, Signature};
use namada::types::transaction::TxType;
use namada_test_utils::TestWasms;
// Use this as `#[test]` annotation to enable logging
Expand Down Expand Up @@ -254,8 +254,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -373,7 +374,8 @@ mod tests {
vp_env.has_valid_pow = true;
let mut tx_data = Tx::new(TxType::Raw);
tx_data.set_data(Data::new(solution_bytes));
tx_data.add_section(Section::Signature(Signature::new(vec![*tx_data.data_sechash()], &target_key)));
tx_data.set_code(Code::new(vec![]));
tx_data.add_section(Section::Signature(Signature::new(vec![*tx_data.data_sechash(), *tx_data.code_sechash()], &target_key)));
let keys_changed: BTreeSet<storage::Key> =
vp_env.all_touched_storage_keys();
let verifiers: BTreeSet<Address> = BTreeSet::default();
Expand Down Expand Up @@ -420,7 +422,8 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash()], &keypair)));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash(), *tx.code_sechash()], &keypair)));
let signed_tx = tx.clone();
vp_env.tx = signed_tx.clone();
let keys_changed: BTreeSet<storage::Key> =
Expand Down
28 changes: 18 additions & 10 deletions wasm/wasm_source/src/vp_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -497,8 +498,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -651,8 +653,9 @@ mod tests {

let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_code(Code::new(vec![]));
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash()], &keypair)));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash(), *tx.code_sechash()], &keypair)));
let signed_tx = tx.clone();
vp_env.tx = signed_tx.clone();
let keys_changed: BTreeSet<storage::Key> =
Expand Down Expand Up @@ -690,6 +693,7 @@ mod tests {
let vp_env = vp_host_env::take();
let mut tx_data = Tx::new(TxType::Raw);
tx_data.set_data(Data::new(vec![]));
tx_data.set_code(Code::new(vec![]));
let keys_changed: BTreeSet<storage::Key> =
vp_env.all_touched_storage_keys();
let verifiers: BTreeSet<Address> = BTreeSet::default();
Expand Down Expand Up @@ -732,8 +736,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -779,8 +784,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -827,8 +833,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -879,8 +886,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -908,8 +916,8 @@ mod tests {
// for the update
tx_env.store_wasm_code(vp_code);

// hardcoded hash of VP_ALWAYS_TRUE_WASM
tx_env.init_parameters(None, None, Some(vec![vp_hash.to_string()]));
let empty_sha256 = sha256(&[]).to_string();
tx_env.init_parameters(None, None, Some(vec![empty_sha256]));

// Spawn the accounts to be able to modify their storage
tx_env.spawn_accounts([&vp_owner]);
Expand All @@ -926,7 +934,7 @@ mod tests {

let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_code(Code::from_hash(vp_hash));
tx.set_code(Code::new(vec![]));
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash(), *tx.code_sechash()],
Expand Down
27 changes: 17 additions & 10 deletions wasm/wasm_source/src/vp_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -518,8 +519,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&secret_key,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -673,7 +675,8 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash()], &keypair)));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(vec![*tx.data_sechash(), *tx.code_sechash()], &keypair)));
let signed_tx = tx.clone();
vp_env.tx = signed_tx.clone();
let keys_changed: BTreeSet<storage::Key> =
Expand Down Expand Up @@ -753,8 +756,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -800,8 +804,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -848,8 +853,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -900,8 +906,9 @@ mod tests {
let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_data(Data::new(vec![]));
tx.set_code(Code::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash()],
vec![*tx.data_sechash(), *tx.code_sechash()],
&keypair,
)));
let signed_tx = tx.clone();
Expand Down Expand Up @@ -929,8 +936,8 @@ mod tests {
// for the update
tx_env.store_wasm_code(vp_code);

// hardcoded hash of VP_ALWAYS_TRUE_WASM
tx_env.init_parameters(None, None, Some(vec![vp_hash.to_string()]));
let empty_sha256 = sha256(&[]).to_string();
tx_env.init_parameters(None, None, Some(vec![empty_sha256]));

// Spawn the accounts to be able to modify their storage
tx_env.spawn_accounts([&vp_owner]);
Expand All @@ -947,7 +954,7 @@ mod tests {

let mut vp_env = vp_host_env::take();
let mut tx = vp_env.tx.clone();
tx.set_code(Code::from_hash(vp_hash));
tx.set_code(Code::new(vec![]));
tx.set_data(Data::new(vec![]));
tx.add_section(Section::Signature(Signature::new(
vec![*tx.data_sechash(), *tx.code_sechash()],
Expand Down

0 comments on commit d52a137

Please sign in to comment.