Skip to content

Commit

Permalink
do not use default when real origin not found (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjj9219 authored Aug 31, 2021
1 parent b4ebb19 commit 8043791
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/currencies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ pub mod module {
Erc20InvalidOperation,
/// EVM account not found
EvmAccountNotFound,
/// Real origin not found
RealOriginNotFound,
}

#[pallet::event]
Expand Down Expand Up @@ -274,7 +276,7 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
match currency_id {
CurrencyId::Erc20(contract) => {
let sender = T::AddressMapping::get_evm_address(from).ok_or(Error::<T>::EvmAccountNotFound)?;
let origin = T::EVMBridge::get_origin().unwrap_or_default();
let origin = T::EVMBridge::get_origin().ok_or(Error::<T>::RealOriginNotFound)?;
let origin_address = T::AddressMapping::get_or_create_evm_address(&origin);
let address = T::AddressMapping::get_or_create_evm_address(to);
T::EVMBridge::transfer(
Expand Down
8 changes: 8 additions & 0 deletions modules/currencies/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,16 @@ fn erc20_transfer_should_fail() {
.build()
.execute_with(|| {
deploy_contracts();

// Real origin not found
assert_noop!(
Currencies::transfer(Origin::signed(alice()), bob(), CurrencyId::Erc20(erc20_address()), 100),
Error::<Runtime>::RealOriginNotFound
);

<EVM as EVMTrait<AccountId>>::set_origin(alice());
<EVM as EVMTrait<AccountId>>::set_origin(bob());

// empty address
assert!(
Currencies::transfer(Origin::signed(alice()), bob(), CurrencyId::Erc20(H160::default()), 100).is_err()
Expand Down

0 comments on commit 8043791

Please sign in to comment.