Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
return value is correctly encoded as a n Address
  • Loading branch information
asiniscalchi committed Aug 7, 2023
commit 1c9e12a64770b9a589810f02e75480ba9d498bd3
5 changes: 3 additions & 2 deletions precompile/living-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use fp_evm::{ExitError, Precompile, PrecompileFailure, PrecompileHandle, Precomp
use pallet_living_assets_ownership::{traits::CollectionManager, CollectionId};
use parity_scale_codec::Encode;
use precompile_utils::{
keccak256, succeed, EvmResult, FunctionModifier, LogExt, LogsBuilder, PrecompileHandleExt,
keccak256, succeed, Address, EvmDataWriter, EvmResult, FunctionModifier, LogExt, LogsBuilder,
PrecompileHandleExt,
};
use sp_runtime::SaturatedConversion;

Expand Down Expand Up @@ -60,7 +61,7 @@ where
.log2(SELECTOR_LOG_CREATE_COLLECTION, collection_address, Vec::new())
.record(handle)?;

Ok(succeed(collection_address.encode()))
Ok(succeed(EvmDataWriter::new().write(Address(collection_address)).build()))
},
Err(err) => Err(PrecompileFailure::Error {
exit_status: ExitError::Other(sp_std::borrow::Cow::Borrowed(err)),
Expand Down
15 changes: 6 additions & 9 deletions precompile/living-assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use super::*;
use evm::ExitRevert;
use helpers::*;
use sp_core::{H160, H256};
use sp_core::H160;
use sp_std::vec::Vec;

type CollectionId = u64;
Expand Down Expand Up @@ -60,14 +60,14 @@ fn create_collection_should_return_address() {
assert!(result.is_ok());
// check that the output is the collection id 0
assert_eq!(
result.unwrap().output,
hex::decode("8000000000000000000000000000000000000005").unwrap()
hex::encode(result.unwrap().output),
"0000000000000000000000008000000000000000000000000000000000000005"
);
}

#[test]
fn create_collection_should_generate_log() {
impl_precompile_mock_simple!(Mock, Ok(5), Some(H160::zero()));
impl_precompile_mock_simple!(Mock, Ok(0xffff), Some(H160::zero()));

let mut handle = create_mock_handle_from_input(CREATE_COLLECTION);
let result = Mock::execute(&mut handle);
Expand All @@ -78,11 +78,8 @@ fn create_collection_should_generate_log() {
assert_eq!(logs[0].topics.len(), 2);
assert_eq!(logs[0].topics[0], SELECTOR_LOG_CREATE_COLLECTION.into());
assert_eq!(
logs[0].topics[1],
H256::from_slice(
&hex::decode("0000000000000000000000008000000000000000000000000000000000000005")
.unwrap()
)
hex::encode(logs[0].topics[1]),
"000000000000000000000000800000000000000000000000000000000000ffff"
);
assert_eq!(logs[0].data, Vec::<u8>::new());
}
Expand Down