-
Notifications
You must be signed in to change notification settings - Fork 992
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1112 from anoma/james/ethbridge/e2e-wrapped-erc20…
…-transfers Ensure wrapped ERC20 transfers are correctly authorized and add end-to-end tests for them
- Loading branch information
Showing
7 changed files
with
802 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,56 @@ | ||
//! Functionality to do with checking whether a transaction is authorized by the | ||
//! "owner" of some key under this account | ||
use eyre::Result; | ||
use namada_core::types::address::Address; | ||
use std::collections::BTreeSet; | ||
|
||
use crate::ledger::native_vp::StorageReader; | ||
use namada_core::types::address::Address; | ||
|
||
/// For wrapped ERC20 transfers, checks that `verifiers` contains the `sender`'s | ||
/// address - we delegate to the sender's VP to authorize the transfer (for | ||
/// regular Namada accounts, this will be `vp_implicit` or `vp_user`). | ||
pub(super) fn is_authorized( | ||
_reader: impl StorageReader, | ||
_tx_data: &[u8], | ||
_owner: &Address, | ||
) -> Result<bool> { | ||
tracing::warn!( | ||
"authorize::is_authorized is not implemented, so all transfers are \ | ||
authorized" | ||
); | ||
Ok(true) | ||
verifiers: &BTreeSet<Address>, | ||
sender: &Address, | ||
receiver: &Address, | ||
) -> bool { | ||
verifiers.contains(sender) && verifiers.contains(receiver) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::ledger::native_vp; | ||
use crate::types::address; | ||
|
||
#[test] | ||
fn test_is_authorized_established_address() -> Result<()> { | ||
let reader = native_vp::testing::FakeStorageReader::default(); | ||
let tx_data = vec![]; | ||
let owner = address::testing::established_address_1(); | ||
fn test_is_authorized_passes() { | ||
let sender = address::testing::established_address_1(); | ||
let receiver = address::testing::established_address_2(); | ||
let verifiers = BTreeSet::from([sender.clone(), receiver.clone()]); | ||
|
||
let authorized = is_authorized(reader, &tx_data, &owner)?; | ||
let authorized = is_authorized(&verifiers, &sender, &receiver); | ||
|
||
assert!(authorized); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_is_authorized_fails() { | ||
let sender = address::testing::established_address_1(); | ||
let receiver = address::testing::established_address_2(); | ||
let verifiers = BTreeSet::default(); | ||
|
||
let authorized = is_authorized(&verifiers, &sender, &receiver); | ||
|
||
assert!(!authorized); | ||
|
||
let verifiers = BTreeSet::from([sender.clone()]); | ||
|
||
let authorized = is_authorized(&verifiers, &sender, &receiver); | ||
|
||
assert!(!authorized); | ||
|
||
let verifiers = BTreeSet::from([receiver.clone()]); | ||
|
||
let authorized = is_authorized(&verifiers, &sender, &receiver); | ||
|
||
assert!(!authorized); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.