Skip to content

Commit

Permalink
Fix attributes dispatch (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraitii committed Aug 23, 2023
1 parent 9cb3152 commit 373b50f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
18 changes: 14 additions & 4 deletions src/attributes/attributes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use briq_protocol::types::{FTSpec, PackedShapeItem};
use briq_protocol::felt_math::{feltBitAnd, feltOrd};
use briq_protocol::cumulative_balance::{CUM_BALANCE_TOKEN, CB_BRIQ, CB_ATTRIBUTES};

use dojo::world::{Context, IWorldDispatcherTrait};
use dojo::world::{Context, IWorldDispatcher, IWorldDispatcherTrait};
use dojo_erc::erc1155::components::ERC1155Balance;
use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig};

Expand All @@ -36,6 +36,16 @@ struct AttributeRemoved {
attribute_id: felt252
}

#[derive(Drop, Serde)]
struct AttributeAssignData {
set_owner: ContractAddress,
set_token_id: felt252,
attribute_id: felt252,
shape: Array<PackedShapeItem>,
fts: Array<FTSpec>,
}


fn assign_attributes(
ctx: Context,
set_owner: ContractAddress,
Expand Down Expand Up @@ -70,9 +80,9 @@ fn assign_attribute(
//library_erc1155::transferability::Transferability::_transfer_burnable(0, set_token_id, attribute_id, 1);
assert(0 == 1, 'TODO');
} else {
let shape_verifier = get!(ctx.world, (attribute_id), ShapeVerifier);
shape_verifier
.assign_attribute(ctx.world, set_owner, set_token_id, attribute_id, shape, fts);
let mut calldata: Array<felt252> = ArrayTrait::new();
AttributeAssignData { set_owner, set_token_id, attribute_id, shape: shape.clone(), fts: fts.clone() }.serialize(ref calldata);
ctx.world.execute(system.unwrap().into(), calldata);
}
emit!(ctx.world, AttributeAssigned { set_token_id: set_token_id.into(), attribute_id });

Expand Down
16 changes: 16 additions & 0 deletions src/check_shape.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,19 @@ mod register_shape_verifier {
set!(ctx.world, ShapeVerifier { attribute_id, class_hash });
}
}

#[system]
mod verify_shape {
use dojo::world::Context;
use super::{ShapeVerifier, CheckShapeTrait};
use briq_protocol::attributes::attributes::AttributeAssignData;

use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig, AdminTrait};

fn execute(ctx: Context, data: AttributeAssignData) {
let AttributeAssignData { set_owner, set_token_id, attribute_id, shape, fts } = data;
let shape_verifier = get!(ctx.world, (attribute_id), ShapeVerifier);
shape_verifier
.assign_attribute(ctx.world, set_owner, set_token_id, attribute_id, @shape, @fts);
}
}
19 changes: 14 additions & 5 deletions src/tests/test_set_nft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn test_simple_mint_attribute_ok() {
{
let mut calldata: Array<felt252> = ArrayTrait::new();
CreateCollectionData {
collection_id: 1, params: 2, admin_or_system: 'check_shape_booklet'.try_into().unwrap()
collection_id: 1, params: 2, admin_or_system: 'verify_shape'.try_into().unwrap()
}.serialize(ref calldata);
world.execute('create_collection', (calldata));
}
Expand Down Expand Up @@ -323,6 +323,9 @@ fn test_simple_mint_attribute_ok() {
'u128_sub Overflow',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED'
)
)]
Expand All @@ -332,7 +335,7 @@ fn test_simple_mint_attribute_dont_have_the_booklet() {
{
let mut calldata: Array<felt252> = ArrayTrait::new();
CreateCollectionData {
collection_id: 1, params: 2, admin_or_system: 'check_shape_booklet'.try_into().unwrap()
collection_id: 1, params: 2, admin_or_system: 'verify_shape'.try_into().unwrap()
}.serialize(ref calldata);
world.execute('create_collection', (calldata));
}
Expand Down Expand Up @@ -397,6 +400,9 @@ fn test_simple_mint_attribute_dont_have_the_booklet() {
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED'
)
)]
Expand All @@ -406,7 +412,7 @@ fn test_simple_mint_attribute_bad_shape_item() {
{
let mut calldata: Array<felt252> = ArrayTrait::new();
CreateCollectionData {
collection_id: 1, params: 2, admin_or_system: 'check_shape_booklet'.try_into().unwrap()
collection_id: 1, params: 2, admin_or_system: 'verify_shape'.try_into().unwrap()
}.serialize(ref calldata);
world.execute('create_collection', (calldata));
}
Expand Down Expand Up @@ -457,6 +463,9 @@ fn test_simple_mint_attribute_bad_shape_item() {
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED',
'ENTRYPOINT_FAILED'
)
)]
Expand All @@ -466,7 +475,7 @@ fn test_simple_mint_attribute_shape_fts_mismatch() {
{
let mut calldata: Array<felt252> = ArrayTrait::new();
CreateCollectionData {
collection_id: 1, params: 2, admin_or_system: 'check_shape_booklet'.try_into().unwrap()
collection_id: 1, params: 2, admin_or_system: 'verify_shape'.try_into().unwrap()
}.serialize(ref calldata);
world.execute('create_collection', (calldata));
}
Expand Down Expand Up @@ -515,7 +524,7 @@ fn test_simple_mint_attribute_forgot_in_disassembly() {
{
let mut calldata: Array<felt252> = ArrayTrait::new();
CreateCollectionData {
collection_id: 1, params: 2, admin_or_system: 'check_shape_booklet'.try_into().unwrap()
collection_id: 1, params: 2, admin_or_system: 'verify_shape'.try_into().unwrap()
}.serialize(ref calldata);
world.execute('create_collection', (calldata));
}
Expand Down
2 changes: 2 additions & 0 deletions src/tests/test_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn spawn_world() -> IWorldDispatcher {
dojo_erc::erc721::components::erc_721_owner::TEST_CLASS_HASH,
dojo_erc::erc721::components::erc_721_token_approval::TEST_CLASS_HASH,
briq_protocol::attributes::collection::collection::TEST_CLASS_HASH,
briq_protocol::check_shape::shape_verifier::TEST_CLASS_HASH,
briq_protocol::world_config::world_config::TEST_CLASS_HASH,
];
// systems
Expand All @@ -49,6 +50,7 @@ fn spawn_world() -> IWorldDispatcher {
briq_protocol::set_nft::systems::set_nft_disassembly::TEST_CLASS_HASH,
briq_protocol::attributes::collection::create_collection::TEST_CLASS_HASH,
briq_protocol::check_shape::register_shape_verifier::TEST_CLASS_HASH,
briq_protocol::check_shape::verify_shape::TEST_CLASS_HASH,
briq_protocol::box_nft::unboxing::box_unboxing::TEST_CLASS_HASH,
briq_protocol::world_config::SetupWorld::TEST_CLASS_HASH,
];
Expand Down

0 comments on commit 373b50f

Please sign in to comment.