Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Adding test for ownerOf with assetId larger than 160b (#114)
Browse files Browse the repository at this point in the history
* create mock and testing

* first test

* testing ethereum reserved addresses

* refactoring

* refactoring

* refactoring tests

* fmt

* erc721 starting point

* fmt

* compiling

* check selectors

* create trait Erc721

* Erc721Precompile

* set mocks

* first implermentation

* first integration of erc721 in the runtime

* fmt

* check on the collection id

* test on extract owner form asset_id

* fix tests

* test for erc721 trait

* fix compilation

* refactoring

* returning address

* return value is correctly encoded as a n Address

* is_erc721_contract is not member of PrecompoileSet

* test on precompiled contracts

* erc721 returns hardcoded address

* refactoring

* testing return of asset ownership

* fix errors

* remove unused use

* refactoring

* rewriting testing mod

* refactoring

* moving check for cllection address in pallet

* Adding test for ownerOf with assetId larger than 160b

* collection address prefix changed

* test passing

* test passing

* refactoring tests

* do not panic the runtime

* fmt

* solidity tokenId -> _tokenId

* erc721 functions are views

* update docs

* sp-core in std , removed duplicate function

* documentaetion

* Extended test to check that two asset ids have the same initial owner by prepending bits to the left

* using compilator type ifer

* minor renaming of test

---------

Co-authored-by: Alessandro Siniscalchi <[email protected]>
  • Loading branch information
tonimateos and asiniscalchi authored Aug 16, 2023
1 parent f10d018 commit a3c9a65
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pallets/living-assets-ownership/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
CollectionError, Event,
};
use frame_support::{assert_err, assert_ok};
use sp_core::H160;
use sp_core::{H160, U256};

type AccountId = <Test as frame_system::Config>::AccountId;

Expand Down Expand Up @@ -136,6 +136,27 @@ fn erc721_owner_of_asset_of_collection() {
});
}

#[test]
fn erc721_owner_of_asset_coincides_for_ids_larger_than_160b() {
new_test_ext().execute_with(|| {
let collection_id =
<LivingAssetsModule as CollectionManager<AccountId>>::create_collection(ALICE).unwrap();
let expected_owner = H160::from_str("931D387731BBBC988B312206C74F77D004D6B84B");
// build two asset ids by prepending "0x1" and "0x2" to the same owner:
let asset_id_1 = U256::from("0x1931D387731BBBC988B312206C74F77D004D6B84B");
let asset_id_2 = U256::from("0x2931D387731BBBC988B312206C74F77D004D6B84B");

assert_eq!(
<LivingAssetsModule as Erc721>::owner_of(collection_id, asset_id_1).unwrap(),
expected_owner.unwrap()
);
assert_eq!(
<LivingAssetsModule as Erc721>::owner_of(collection_id, asset_id_2).unwrap(),
expected_owner.unwrap()
);
});
}

#[test]
fn test_collection_id_to_address() {
let collection_id = 5;
Expand Down

0 comments on commit a3c9a65

Please sign in to comment.