create-dubhe 1.2.0-pre.98 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +16 -16
- package/templates/101/sui-template/docker-compose.testnet.yml +73 -0
- package/templates/101/sui-template/packages/client/src/app/page.tsx +545 -41
- package/templates/101/sui-template/packages/client/src/app/providers.tsx +12 -4
- package/templates/101/sui-template/packages/contracts/Pub.localnet.toml +4 -4
- package/templates/101/sui-template/packages/contracts/counter.lock.json +20 -0
- package/templates/101/sui-template/packages/contracts/deployment.ts +8 -3
- package/templates/101/sui-template/packages/contracts/dubhe.config.json +59 -13
- package/templates/101/sui-template/packages/contracts/dubhe.config.ts +1 -4
- package/templates/101/sui-template/packages/contracts/metadata.json +1015 -68
- package/templates/101/sui-template/packages/contracts/package.json +7 -4
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +45 -31
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/error.move +8 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/genesis.move +30 -13
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/init_test.move +19 -14
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2.move +198 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2withkey.move +90 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/value.move +30 -20
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/scripts/deploy_hook.move +6 -11
- package/templates/101/sui-template/packages/contracts/src/counter/sources/systems/counter.move +23 -11
- package/templates/101/sui-template/packages/contracts/src/counter/sources/tests/counter.move +15 -14
- package/templates/101/sui-template/packages/contracts/src/dubhe/Move.lock +33 -30
- package/templates/101/sui-template/packages/contracts/src/dubhe/Move.toml +8 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +45 -31
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +170 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +16 -13
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/init_test.move +8 -14
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/account_key.move +1 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +1776 -137
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/data_key.move +1 -20
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/events.move +864 -25
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +15 -16
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/scripts/migrate.move +0 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/address_system.move +25 -17
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +2802 -343
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/utils.move +1 -1
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/address.move +173 -55
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/dapp_test.move +769 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2965 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +303 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +1422 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/scene_session_test.move +269 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/session_test.move +624 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/storage_test.move +700 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +177 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +452 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +160 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/utils/math.move +4 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/utils/type_info.move +2 -2
- package/templates/contract/sui-template/dubhe.config.ts +0 -1
- package/templates/contract/sui-template/package.json +3 -3
- package/templates/contract/sui-template/src/dubhe/Move.lock +33 -30
- package/templates/contract/sui-template/src/dubhe/Move.toml +8 -3
- package/templates/contract/sui-template/src/dubhe/sources/codegen/dapp_key.move +45 -31
- package/templates/contract/sui-template/src/dubhe/sources/codegen/error.move +170 -0
- package/templates/contract/sui-template/src/dubhe/sources/codegen/genesis.move +16 -13
- package/templates/contract/sui-template/src/dubhe/sources/codegen/init_test.move +8 -14
- package/templates/contract/sui-template/src/dubhe/sources/core/account_key.move +1 -3
- package/templates/contract/sui-template/src/dubhe/sources/core/dapp_service.move +1776 -137
- package/templates/contract/sui-template/src/dubhe/sources/core/data_key.move +1 -20
- package/templates/contract/sui-template/src/dubhe/sources/core/events.move +864 -25
- package/templates/contract/sui-template/src/dubhe/sources/scripts/deploy_hook.move +15 -16
- package/templates/contract/sui-template/src/dubhe/sources/scripts/migrate.move +0 -3
- package/templates/contract/sui-template/src/dubhe/sources/systems/address_system.move +25 -17
- package/templates/contract/sui-template/src/dubhe/sources/systems/dapp_system.move +2802 -343
- package/templates/contract/sui-template/src/dubhe/sources/systems/utils.move +1 -1
- package/templates/contract/sui-template/src/dubhe/sources/tests/address.move +173 -55
- package/templates/contract/sui-template/src/dubhe/sources/tests/dapp_test.move +769 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/fee_test.move +2965 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/integration_test.move +303 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/listing_test.move +1422 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/scene_session_test.move +269 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/session_test.move +624 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/storage_test.move +700 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/typed_object_test.move +177 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/typed_scene_test.move +452 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/user_storage_test.move +160 -0
- package/templates/contract/sui-template/src/dubhe/sources/utils/math.move +4 -3
- package/templates/contract/sui-template/src/dubhe/sources/utils/type_info.move +2 -2
- package/templates/contract/sui-template/src/template/Move.toml +12 -0
- package/templates/contract/sui-template/src/template/sources/codegen/dapp_key.move +47 -0
- package/templates/contract/sui-template/src/template/sources/codegen/genesis.move +34 -0
- package/templates/contract/sui-template/src/template/sources/codegen/init_test.move +23 -0
- package/templates/contract/sui-template/src/template/sources/codegen/user_storage_init.move +27 -0
- package/templates/contract/sui-template/src/template/sources/scripts/deploy_hook.move +13 -0
- package/templates/contract/sui-template/src/template/sources/scripts/migrate.move +7 -0
- package/templates/nextjs/sui-card-duel/.gitignore_ +51 -0
- package/templates/nextjs/sui-card-duel/README.md +213 -0
- package/templates/nextjs/sui-card-duel/docker-compose.yml +34 -0
- package/templates/nextjs/sui-card-duel/mprocs.yaml +17 -0
- package/templates/nextjs/sui-card-duel/package.json +43 -0
- package/templates/nextjs/sui-card-duel/packages/client/.gitignore_ +48 -0
- package/templates/nextjs/sui-card-duel/packages/client/.prettierignore +1 -0
- package/templates/nextjs/sui-card-duel/packages/client/.prettierrc.json +8 -0
- package/templates/nextjs/sui-card-duel/packages/client/eslint.config.mjs +22 -0
- package/templates/nextjs/sui-card-duel/packages/client/next.config.mjs +8 -0
- package/templates/nextjs/sui-card-duel/packages/client/package.json +47 -0
- package/templates/nextjs/sui-card-duel/packages/client/postcss.config.mjs +8 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/admin/ArenaPanel.tsx +307 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/admin/page.tsx +622 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/brawl/[id]/page.tsx +559 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/collection/page.tsx +202 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/components/CardView.tsx +66 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/components/GameShell.tsx +294 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/components/icons.tsx +101 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/duel/[id]/page.tsx +477 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/favicon.ico +0 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/globals.css +85 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/hooks/useGame.ts +313 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/layout.tsx +24 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/leaderboard/page.tsx +123 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/lib/game.ts +77 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/lib/scenes.ts +226 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/market/page.tsx +418 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/page.tsx +427 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/providers.tsx +69 -0
- package/templates/nextjs/sui-card-duel/packages/client/tailwind.config.ts +21 -0
- package/templates/nextjs/sui-card-duel/packages/client/tsconfig.json +30 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/.gitignore_ +51 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/.prettierignore +1 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/.prettierrc.json +8 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/Dockerfile +5 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/Pub.localnet.toml +13 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/card_duel.lock.json +66 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/docker-compose.yml +34 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/dubhe.config.ts +150 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/logs/combined.log +31383 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/package.json +49 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/config.ts +17 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-brawl.ts +270 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-duel.ts +272 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-lobby.ts +177 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-market.ts +219 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-session.ts +342 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/query-dapp-revenue.ts +95 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/seed.ts +92 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/withdraw-dapp-revenue.ts +56 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/Move.toml +15 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/dapp_key.move +46 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/card_kind.move +47 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/match_state.move +37 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/rarity.move +37 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/error.move +126 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/genesis.move +33 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/init_test.move +23 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/objects/arena.move +137 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/permits/brawl_permit.move +125 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/permits/duel_permit.move +125 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/battle_state.move +255 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/card.move +282 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/deck.move +64 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/game_config.move +267 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/gold.move +205 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/profile.move +255 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/scenes/brawl.move +313 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/scenes/duel.move +313 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/scripts/deploy_hook.move +32 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/scripts/migrate.move +7 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/arena_system.move +57 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/brawl_system.move +559 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/card_system.move +146 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/duel_system.move +515 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/market_system.move +115 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/player_system.move +37 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/brawl_tests.move +385 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/duel_tests.move +656 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/test_helpers.move +31 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/sui-indexer-schema.graphql +5973 -0
- package/templates/nextjs/sui-card-duel/pnpm-workspace.yaml +2 -0
- package/templates/nextjs/sui-farm/.gitignore_ +51 -0
- package/templates/nextjs/sui-farm/README.md +15 -0
- package/templates/nextjs/sui-farm/UPGRADE_NOTES.md +97 -0
- package/templates/nextjs/sui-farm/docker-compose.yml +34 -0
- package/templates/nextjs/sui-farm/mprocs.yaml +17 -0
- package/templates/nextjs/sui-farm/package.json +43 -0
- package/templates/nextjs/sui-farm/packages/client/.gitignore_ +48 -0
- package/templates/nextjs/sui-farm/packages/client/.prettierignore +1 -0
- package/templates/nextjs/sui-farm/packages/client/.prettierrc.json +8 -0
- package/templates/nextjs/sui-farm/packages/client/eslint.config.mjs +22 -0
- package/templates/nextjs/sui-farm/packages/client/next.config.mjs +8 -0
- package/templates/nextjs/sui-farm/packages/client/package.json +47 -0
- package/templates/nextjs/sui-farm/packages/client/postcss.config.mjs +8 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/admin/page.tsx +618 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/FarmLand.tsx +526 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/FarmPlotCard.tsx +215 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/PetAvatar.tsx +868 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/PetPanel.tsx +1360 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/PlantModal.tsx +147 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ProxyCard.tsx +684 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/RanchLand.tsx +822 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ResourceHUD.tsx +125 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ShopPanel.tsx +232 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/icons/GameIcons.tsx +574 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/favicon.ico +0 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/globals.css +423 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/hooks/useWorldPermitId.ts +66 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/layout.tsx +23 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/leaderboard/page.tsx +185 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/lib/crops.ts +97 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/market/page.tsx +763 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/page.tsx +1173 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/providers.tsx +69 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/state/index.tsx +5 -0
- package/templates/nextjs/sui-farm/packages/client/tailwind.config.ts +25 -0
- package/templates/nextjs/sui-farm/packages/client/tsconfig.json +30 -0
- package/templates/nextjs/sui-farm/packages/contracts/.gitignore_ +51 -0
- package/templates/nextjs/sui-farm/packages/contracts/.prettierignore +1 -0
- package/templates/nextjs/sui-farm/packages/contracts/.prettierrc.json +8 -0
- package/templates/nextjs/sui-farm/packages/contracts/Dockerfile +5 -0
- package/templates/nextjs/sui-farm/packages/contracts/Pub.localnet.toml +13 -0
- package/templates/nextjs/sui-farm/packages/contracts/counter.lock.json +14 -0
- package/templates/nextjs/sui-farm/packages/contracts/docker-compose.yml +34 -0
- package/templates/nextjs/sui-farm/packages/contracts/dubhe.config.ts +178 -0
- package/templates/nextjs/sui-farm/packages/contracts/harvest.lock.json +120 -0
- package/templates/nextjs/sui-farm/packages/contracts/package.json +48 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/config.ts +17 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/query-dapp-revenue.ts +95 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/read-permit.ts +72 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/seed.ts +85 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/withdraw-dapp-revenue.ts +56 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/Move.toml +14 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/dapp_key.move +31 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/error.move +10 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/genesis.move +33 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/init_test.move +23 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/resources/counter1.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/resources/counter2.move +70 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/scripts/deploy_hook.move +8 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/scripts/migrate.move +8 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/systems/counter.move +13 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/tests/counter.move +28 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/Move.toml +14 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/dapp_key.move +46 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/crop_type.move +47 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/egg_type.move +42 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/pet_rarity.move +37 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/pet_species.move +52 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/error.move +110 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/genesis.move +33 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/init_test.move +23 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/permits/world.move +125 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/carrot.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/carrot_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/common_egg.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/corn.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/corn_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/crow_charges.move +162 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/crow_damage.move +207 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/farm_plot.move +261 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/gold.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet.move +467 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_config.move +372 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_hatch.move +162 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_slot_index.move +83 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_slots.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/profile.move +162 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pumpkin.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pumpkin_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/rare_egg.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/scarecrow.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/season_config.move +197 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/season_stats.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/seasonal_egg.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/shop_config.move +267 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/trophy.move +245 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/wheat.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/wheat_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/world_permit_id.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/scripts/deploy_hook.move +45 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/scripts/migrate.move +7 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/crow_system.move +96 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/farm_system.move +182 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/market_system.move +172 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/pet_system.move +495 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/season_system.move +70 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/shop_system.move +112 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/world_system.move +34 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/tests/farm_tests.move +1192 -0
- package/templates/nextjs/sui-farm/pnpm-workspace.yaml +2 -0
- package/templates/nextjs/sui-template/packages/client/src/app/components/ProxyCard.tsx +683 -0
- package/templates/nextjs/sui-template/packages/client/src/app/page.tsx +510 -5
- package/templates/nextjs/sui-template/packages/client/src/app/providers.tsx +13 -5
- package/templates/nextjs/sui-template/packages/contracts/Pub.localnet.toml +4 -4
- package/templates/nextjs/sui-template/packages/contracts/counter.lock.json +14 -0
- package/templates/nextjs/sui-template/packages/contracts/deployment.ts +8 -3
- package/templates/nextjs/sui-template/packages/contracts/dubhe.config.json +9 -9
- package/templates/nextjs/sui-template/packages/contracts/dubhe.config.ts +0 -4
- package/templates/nextjs/sui-template/packages/contracts/metadata.json +180 -124
- package/templates/nextjs/sui-template/packages/contracts/package.json +8 -4
- package/templates/nextjs/sui-template/packages/contracts/src/counter/Move.toml +4 -0
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +45 -31
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/error.move +10 -0
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/genesis.move +30 -13
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/init_test.move +19 -14
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter1.move +30 -20
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2.move +35 -24
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/scripts/deploy_hook.move +6 -10
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/systems/counter.move +7 -20
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/tests/counter.move +14 -27
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.lock +33 -30
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.toml +8 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +45 -31
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +170 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +16 -13
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/init_test.move +8 -14
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/account_key.move +1 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +1776 -137
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/data_key.move +1 -20
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/events.move +864 -25
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +15 -16
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/scripts/migrate.move +0 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/address_system.move +25 -17
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +2802 -343
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/utils.move +1 -1
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/address.move +173 -55
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/dapp_test.move +769 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2965 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +303 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +1422 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/scene_session_test.move +269 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/session_test.move +624 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/storage_test.move +700 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +177 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +452 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +160 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/utils/math.move +4 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/utils/type_info.move +2 -2
- package/templates/101/sui-template/packages/contracts/src/counter/Move.lock +0 -41
- package/templates/101/sui-template/packages/contracts/src/counter/Published.toml +0 -9
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/errors.move +0 -12
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +0 -140
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +0 -29
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/session_system.move +0 -44
- package/templates/contract/sui-template/src/dubhe/sources/codegen/errors.move +0 -140
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
- package/templates/contract/sui-template/src/dubhe/sources/core/dapp_store.move +0 -29
- package/templates/contract/sui-template/src/dubhe/sources/systems/session_system.move +0 -44
- package/templates/nextjs/sui-template/packages/contracts/src/counter/Move.lock +0 -47
- package/templates/nextjs/sui-template/packages/contracts/src/counter/Published.toml +0 -9
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/errors.move +0 -12
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +0 -140
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +0 -29
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/session_system.move +0 -44
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/// Unit tests — Typed ObjectStorage (entity_id uniqueness + adminOnly guard)
|
|
2
|
+
///
|
|
3
|
+
/// Covers:
|
|
4
|
+
/// - create_object / destroy_object framework primitives
|
|
5
|
+
/// - entity_id uniqueness enforcement within a type_tag
|
|
6
|
+
/// - Different type_tags can share the same entity_id bytes without collision
|
|
7
|
+
/// - has_object_entity_id / get_object_entity_id read helpers
|
|
8
|
+
/// - destroy_typed_object aborts when DApp is paused
|
|
9
|
+
#[test_only]
|
|
10
|
+
module dubhe::typed_object_test;
|
|
11
|
+
|
|
12
|
+
use dubhe::dapp_service::{Self, DappStorage};
|
|
13
|
+
use dubhe::dapp_system;
|
|
14
|
+
|
|
15
|
+
public struct ObjectKey has copy, drop {}
|
|
16
|
+
public struct OtherKey has copy, drop {}
|
|
17
|
+
|
|
18
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
fun make_ds(ctx: &mut TxContext): DappStorage {
|
|
21
|
+
dapp_service::create_dapp_storage_for_testing<ObjectKey>(ctx)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ─── create_object: happy path ────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
#[test]
|
|
27
|
+
fun test_create_object_registers_entity_id() {
|
|
28
|
+
let mut ctx = sui::tx_context::dummy();
|
|
29
|
+
let mut ds = make_ds(&mut ctx);
|
|
30
|
+
|
|
31
|
+
let uid = dapp_system::create_object<ObjectKey>(
|
|
32
|
+
ObjectKey {}, &mut ds, b"guild", b"guild_001", &mut ctx,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
assert!(dapp_service::has_object_entity_id(&ds, b"guild", b"guild_001"), 0);
|
|
36
|
+
|
|
37
|
+
let stored_addr = dapp_service::get_object_entity_id(&ds, b"guild", b"guild_001");
|
|
38
|
+
assert!(stored_addr == object::uid_to_address(&uid), 1);
|
|
39
|
+
|
|
40
|
+
object::delete(uid);
|
|
41
|
+
dapp_service::destroy_dapp_storage(ds);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ─── entity_id uniqueness within same type_tag ────────────────────────────────
|
|
45
|
+
|
|
46
|
+
#[test]
|
|
47
|
+
#[expected_failure]
|
|
48
|
+
fun test_duplicate_entity_id_same_type_aborts() {
|
|
49
|
+
let mut ctx = sui::tx_context::dummy();
|
|
50
|
+
let mut ds = make_ds(&mut ctx);
|
|
51
|
+
|
|
52
|
+
let uid1 = dapp_system::create_object<ObjectKey>(
|
|
53
|
+
ObjectKey {}, &mut ds, b"guild", b"dup_id", &mut ctx,
|
|
54
|
+
);
|
|
55
|
+
// Second create with same (type_tag, entity_id) must abort.
|
|
56
|
+
let uid2 = dapp_system::create_object<ObjectKey>(
|
|
57
|
+
ObjectKey {}, &mut ds, b"guild", b"dup_id", &mut ctx,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
object::delete(uid1);
|
|
61
|
+
object::delete(uid2);
|
|
62
|
+
dapp_service::destroy_dapp_storage(ds);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ─── different type_tags may share the same entity_id ─────────────────────────
|
|
66
|
+
|
|
67
|
+
#[test]
|
|
68
|
+
fun test_same_entity_id_different_type_tags_ok() {
|
|
69
|
+
let mut ctx = sui::tx_context::dummy();
|
|
70
|
+
let mut ds = make_ds(&mut ctx);
|
|
71
|
+
|
|
72
|
+
// A guild and a boss can both be called b"leader" without conflict.
|
|
73
|
+
let uid_guild = dapp_system::create_object<ObjectKey>(
|
|
74
|
+
ObjectKey {}, &mut ds, b"guild", b"leader", &mut ctx,
|
|
75
|
+
);
|
|
76
|
+
let uid_boss = dapp_system::create_object<ObjectKey>(
|
|
77
|
+
ObjectKey {}, &mut ds, b"boss", b"leader", &mut ctx,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
assert!(dapp_service::has_object_entity_id(&ds, b"guild", b"leader"), 0);
|
|
81
|
+
assert!(dapp_service::has_object_entity_id(&ds, b"boss", b"leader"), 1);
|
|
82
|
+
|
|
83
|
+
object::delete(uid_guild);
|
|
84
|
+
object::delete(uid_boss);
|
|
85
|
+
dapp_service::destroy_dapp_storage(ds);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ─── destroy_object cleans up the mapping ────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
#[test]
|
|
91
|
+
fun test_destroy_object_removes_entity_id() {
|
|
92
|
+
let mut ctx = sui::tx_context::dummy();
|
|
93
|
+
let mut ds = make_ds(&mut ctx);
|
|
94
|
+
|
|
95
|
+
let uid = dapp_system::create_object<ObjectKey>(
|
|
96
|
+
ObjectKey {}, &mut ds, b"guild", b"to_destroy", &mut ctx,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
assert!(dapp_service::has_object_entity_id(&ds, b"guild", b"to_destroy"), 0);
|
|
100
|
+
|
|
101
|
+
dapp_system::destroy_object<ObjectKey>(ObjectKey {}, &mut ds, b"guild", b"to_destroy", uid);
|
|
102
|
+
|
|
103
|
+
assert!(!dapp_service::has_object_entity_id(&ds, b"guild", b"to_destroy"), 1);
|
|
104
|
+
|
|
105
|
+
dapp_service::destroy_dapp_storage(ds);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ─── entity_id can be reused after destroy ────────────────────────────────────
|
|
109
|
+
|
|
110
|
+
#[test]
|
|
111
|
+
fun test_entity_id_reuse_after_destroy() {
|
|
112
|
+
let mut ctx = sui::tx_context::dummy();
|
|
113
|
+
let mut ds = make_ds(&mut ctx);
|
|
114
|
+
|
|
115
|
+
let uid1 = dapp_system::create_object<ObjectKey>(
|
|
116
|
+
ObjectKey {}, &mut ds, b"guild", b"reuse_id", &mut ctx,
|
|
117
|
+
);
|
|
118
|
+
dapp_system::destroy_object<ObjectKey>(ObjectKey {}, &mut ds, b"guild", b"reuse_id", uid1);
|
|
119
|
+
|
|
120
|
+
// Should succeed now.
|
|
121
|
+
let uid2 = dapp_system::create_object<ObjectKey>(
|
|
122
|
+
ObjectKey {}, &mut ds, b"guild", b"reuse_id", &mut ctx,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
assert!(dapp_service::has_object_entity_id(&ds, b"guild", b"reuse_id"), 0);
|
|
126
|
+
|
|
127
|
+
object::delete(uid2);
|
|
128
|
+
dapp_service::destroy_dapp_storage(ds);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ─── dapp_key_mismatch guard ──────────────────────────────────────────────────
|
|
132
|
+
|
|
133
|
+
#[test]
|
|
134
|
+
#[expected_failure]
|
|
135
|
+
fun test_create_object_wrong_dapp_key_aborts() {
|
|
136
|
+
let mut ctx = sui::tx_context::dummy();
|
|
137
|
+
// ds is bound to ObjectKey, but we try to create with OtherKey.
|
|
138
|
+
let mut ds = make_ds(&mut ctx);
|
|
139
|
+
|
|
140
|
+
let uid = dapp_system::create_object<OtherKey>(
|
|
141
|
+
OtherKey {}, &mut ds, b"guild", b"mismatch", &mut ctx,
|
|
142
|
+
);
|
|
143
|
+
object::delete(uid);
|
|
144
|
+
dapp_service::destroy_dapp_storage(ds);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ─── Pause guard: destroy_typed_object aborts when DApp is paused ─────────────
|
|
148
|
+
|
|
149
|
+
/// Phantom marker type used only in the pause test below.
|
|
150
|
+
public struct ObjMarker has copy, drop {}
|
|
151
|
+
|
|
152
|
+
/// destroy_typed_object must abort with EDappPaused when the DApp is paused.
|
|
153
|
+
/// An ObjectStorage<ObjMarker> is constructed directly via new_object_storage
|
|
154
|
+
/// (package-internal) so that we can control its lifecycle without going through
|
|
155
|
+
/// create_and_share_typed_object (which would make it a shared object).
|
|
156
|
+
/// Because this is #[expected_failure] the Move test VM discards the
|
|
157
|
+
/// ObjectStorage created before the abort without requiring an explicit cleanup.
|
|
158
|
+
#[test]
|
|
159
|
+
#[expected_failure]
|
|
160
|
+
fun test_destroy_typed_object_aborts_when_paused() {
|
|
161
|
+
let mut ctx = sui::tx_context::dummy();
|
|
162
|
+
let dh = dapp_service::create_dapp_hub_for_testing(&mut ctx);
|
|
163
|
+
let mut ds = make_ds(&mut ctx);
|
|
164
|
+
|
|
165
|
+
// Build a matching ObjectStorage<ObjMarker> directly.
|
|
166
|
+
let dapp_key_str = dapp_service::dapp_storage_dapp_key(&ds);
|
|
167
|
+
let storage = dapp_service::new_object_storage<ObjMarker>(
|
|
168
|
+
dapp_key_str, b"obj_marker", b"id_01", &mut ctx,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Pause the DApp — destroy_typed_object must now abort.
|
|
172
|
+
dapp_system::set_paused<ObjectKey>(&dh, &mut ds, true, &mut ctx);
|
|
173
|
+
// Must abort here — unreachable cleanup required by Move compiler.
|
|
174
|
+
dapp_system::destroy_typed_object<ObjectKey, ObjMarker>(ObjectKey {}, &mut ds, storage);
|
|
175
|
+
dapp_service::destroy_dapp_hub(dh);
|
|
176
|
+
dapp_service::destroy_dapp_storage(ds);
|
|
177
|
+
}
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/// Unit tests — Typed SceneStorage and reactive writes
|
|
2
|
+
///
|
|
3
|
+
/// Covers:
|
|
4
|
+
/// - ScenePermit participant management (O(1) dynamic fields)
|
|
5
|
+
/// - is_scene_active / is_participant_in_scene_permit
|
|
6
|
+
/// - set_record_reactive: four-layer security checks
|
|
7
|
+
/// - set_field_reactive: same security model
|
|
8
|
+
/// - Invitation flow: create_with_invitations + accept_scene_permit_invitation
|
|
9
|
+
#[test_only]
|
|
10
|
+
module dubhe::typed_scene_test;
|
|
11
|
+
|
|
12
|
+
use dubhe::dapp_service::{Self, UserStorage, ScenePermit};
|
|
13
|
+
use dubhe::dapp_system;
|
|
14
|
+
use sui::bcs::to_bytes;
|
|
15
|
+
use sui::tx_context;
|
|
16
|
+
|
|
17
|
+
public struct SceneKey has copy, drop {}
|
|
18
|
+
|
|
19
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
fun make_us(owner: address, ctx: &mut TxContext): UserStorage {
|
|
22
|
+
dapp_service::create_user_storage_for_testing<SceneKey>(owner, ctx)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Create a ScenePermit with confirmed participants.
|
|
26
|
+
fun make_permit(
|
|
27
|
+
participants: vector<address>,
|
|
28
|
+
expires_at: std::option::Option<u64>,
|
|
29
|
+
ctx: &mut TxContext,
|
|
30
|
+
): ScenePermit<SceneKey> {
|
|
31
|
+
dapp_service::create_scene_permit_for_testing<SceneKey, SceneKey>(
|
|
32
|
+
participants, expires_at, std::option::none(), ctx,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Create a ScenePermit with a participant cap.
|
|
37
|
+
fun make_permit_with_cap(
|
|
38
|
+
participants: vector<address>,
|
|
39
|
+
max_participants: u64,
|
|
40
|
+
ctx: &mut TxContext,
|
|
41
|
+
): ScenePermit<SceneKey> {
|
|
42
|
+
dapp_service::create_scene_permit_for_testing<SceneKey, SceneKey>(
|
|
43
|
+
participants, std::option::none(), std::option::some(max_participants), ctx,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// Create a ScenePermit in invitation mode (no confirmed participants yet).
|
|
48
|
+
fun make_permit_with_invitations(
|
|
49
|
+
invitees: vector<address>,
|
|
50
|
+
invites_expire_at: std::option::Option<u64>,
|
|
51
|
+
expires_at: std::option::Option<u64>,
|
|
52
|
+
ctx: &mut TxContext,
|
|
53
|
+
): ScenePermit<SceneKey> {
|
|
54
|
+
dapp_service::create_scene_permit_with_invitations_for_testing<SceneKey, SceneKey>(
|
|
55
|
+
invitees, invites_expire_at, expires_at, ctx,
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fun make_permanent_permit(
|
|
60
|
+
participants: vector<address>,
|
|
61
|
+
ctx: &mut TxContext,
|
|
62
|
+
): ScenePermit<SceneKey> {
|
|
63
|
+
make_permit(participants, std::option::none(), ctx)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fun key_for(name: vector<u8>): vector<vector<u8>> { vector[name] }
|
|
67
|
+
fun fns(): vector<vector<u8>> { vector[b"v"] }
|
|
68
|
+
fun u64_val(v: u64): vector<vector<u8>> { vector[to_bytes(&v)] }
|
|
69
|
+
|
|
70
|
+
// ─── ScenePermit participant management ───────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
#[test]
|
|
73
|
+
fun test_add_remove_permit_participant() {
|
|
74
|
+
let mut ctx = sui::tx_context::dummy();
|
|
75
|
+
let mut permit = make_permanent_permit(vector[@0xAAAA], &mut ctx);
|
|
76
|
+
|
|
77
|
+
assert!(!dapp_service::is_participant_in_scene_permit(&permit, @0xBBBB), 0);
|
|
78
|
+
assert!(dapp_service::scene_participant_count(dapp_service::scene_permit_meta(&permit)) == 1, 1);
|
|
79
|
+
|
|
80
|
+
dapp_service::add_participant_in_scene_permit(&mut permit, @0xBBBB);
|
|
81
|
+
assert!(dapp_service::is_participant_in_scene_permit(&permit, @0xBBBB), 2);
|
|
82
|
+
assert!(dapp_service::scene_participant_count(dapp_service::scene_permit_meta(&permit)) == 2, 3);
|
|
83
|
+
|
|
84
|
+
dapp_service::remove_participant_in_scene_permit(&mut permit, @0xBBBB);
|
|
85
|
+
assert!(!dapp_service::is_participant_in_scene_permit(&permit, @0xBBBB), 4);
|
|
86
|
+
assert!(dapp_service::scene_participant_count(dapp_service::scene_permit_meta(&permit)) == 1, 5);
|
|
87
|
+
|
|
88
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#[test]
|
|
92
|
+
fun test_add_participant_idempotent() {
|
|
93
|
+
let mut ctx = sui::tx_context::dummy();
|
|
94
|
+
let mut permit = make_permanent_permit(vector[@0xA], &mut ctx);
|
|
95
|
+
|
|
96
|
+
dapp_service::add_participant_in_scene_permit(&mut permit, @0xA);
|
|
97
|
+
assert!(dapp_service::scene_participant_count(dapp_service::scene_permit_meta(&permit)) == 1, 0);
|
|
98
|
+
|
|
99
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#[test]
|
|
103
|
+
fun test_remove_nonexistent_participant_noop() {
|
|
104
|
+
let mut ctx = sui::tx_context::dummy();
|
|
105
|
+
let mut permit = make_permanent_permit(vector[@0xA], &mut ctx);
|
|
106
|
+
|
|
107
|
+
dapp_service::remove_participant_in_scene_permit(&mut permit, @0xB);
|
|
108
|
+
assert!(dapp_service::scene_participant_count(dapp_service::scene_permit_meta(&permit)) == 1, 0);
|
|
109
|
+
|
|
110
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#[test]
|
|
114
|
+
#[expected_failure]
|
|
115
|
+
fun test_max_participants_cap_enforced() {
|
|
116
|
+
let mut ctx = sui::tx_context::dummy();
|
|
117
|
+
let mut permit = make_permit_with_cap(vector[@0xA], 1, &mut ctx);
|
|
118
|
+
|
|
119
|
+
dapp_service::add_participant_in_scene_permit(&mut permit, @0xB);
|
|
120
|
+
|
|
121
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ─── PermitMetadata basics ─────────────────────────────────────────────────────
|
|
125
|
+
|
|
126
|
+
#[test]
|
|
127
|
+
fun test_scene_expires_at_accessor() {
|
|
128
|
+
let mut ctx = sui::tx_context::dummy();
|
|
129
|
+
|
|
130
|
+
let permit_perm = make_permanent_permit(vector[@0xA], &mut ctx);
|
|
131
|
+
assert!(dapp_service::scene_expires_at(dapp_service::scene_permit_meta(&permit_perm)).is_none(), 0);
|
|
132
|
+
dapp_service::destroy_scene_permit_for_testing(permit_perm);
|
|
133
|
+
|
|
134
|
+
let permit_exp = make_permit(vector[@0xA], std::option::some(9_999), &mut ctx);
|
|
135
|
+
let opt = dapp_service::scene_expires_at(dapp_service::scene_permit_meta(&permit_exp));
|
|
136
|
+
assert!(opt.is_some(), 1);
|
|
137
|
+
assert!(*opt.borrow() == 9_999, 2);
|
|
138
|
+
dapp_service::destroy_scene_permit_for_testing(permit_exp);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[test]
|
|
142
|
+
fun test_scene_meta_active_with_none_expiry() {
|
|
143
|
+
let mut ctx = sui::tx_context::dummy();
|
|
144
|
+
let permit = make_permanent_permit(vector[@0xA, @0xB], &mut ctx);
|
|
145
|
+
assert!(dapp_service::is_scene_active(dapp_service::scene_permit_meta(&permit), 0), 0);
|
|
146
|
+
assert!(dapp_service::is_scene_active(dapp_service::scene_permit_meta(&permit), 999_999_999_999), 1);
|
|
147
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#[test]
|
|
151
|
+
fun test_scene_meta_active_before_expiry() {
|
|
152
|
+
let mut ctx = sui::tx_context::dummy();
|
|
153
|
+
let permit = make_permit(vector[@0xA], std::option::some(1_000_000), &mut ctx);
|
|
154
|
+
assert!(dapp_service::is_scene_active(dapp_service::scene_permit_meta(&permit), 999_999), 0);
|
|
155
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#[test]
|
|
159
|
+
fun test_scene_meta_expired_at_deadline() {
|
|
160
|
+
let mut ctx = sui::tx_context::dummy();
|
|
161
|
+
let permit = make_permit(vector[@0xA], std::option::some(1_000_000), &mut ctx);
|
|
162
|
+
assert!(!dapp_service::is_scene_active(dapp_service::scene_permit_meta(&permit), 1_000_000), 0);
|
|
163
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
#[test]
|
|
167
|
+
fun test_scene_meta_participant_check() {
|
|
168
|
+
let mut ctx = sui::tx_context::dummy();
|
|
169
|
+
let permit = make_permanent_permit(vector[@0xA, @0xB], &mut ctx);
|
|
170
|
+
assert!(dapp_service::is_participant_in_scene_permit(&permit, @0xA), 0);
|
|
171
|
+
assert!(dapp_service::is_participant_in_scene_permit(&permit, @0xB), 1);
|
|
172
|
+
assert!(!dapp_service::is_participant_in_scene_permit(&permit, @0xC), 2);
|
|
173
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ─── set_record_reactive: happy path ─────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
#[test]
|
|
179
|
+
fun test_set_record_reactive_ok() {
|
|
180
|
+
let mut ctx = sui::tx_context::dummy();
|
|
181
|
+
let sender = ctx.sender();
|
|
182
|
+
|
|
183
|
+
let permit = make_permanent_permit(vector[sender, @0xBBBB], &mut ctx);
|
|
184
|
+
let mut from = make_us(sender, &mut ctx);
|
|
185
|
+
let mut target = make_us(@0xBBBB, &mut ctx);
|
|
186
|
+
|
|
187
|
+
dapp_system::set_record_reactive<SceneKey, SceneKey>(
|
|
188
|
+
SceneKey {}, &permit, &mut from, &mut target,
|
|
189
|
+
key_for(b"hp"), fns(), u64_val(100), &mut ctx,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
assert!(dapp_service::has_user_record<SceneKey>(&target, key_for(b"hp")), 0);
|
|
193
|
+
assert!(dapp_service::write_count(&from) == 1, 1);
|
|
194
|
+
assert!(dapp_service::write_count(&target) == 0, 2);
|
|
195
|
+
|
|
196
|
+
dapp_service::destroy_user_storage(from);
|
|
197
|
+
dapp_service::destroy_user_storage(target);
|
|
198
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ─── set_record_reactive: initiator not in scene ─────────────────────────────
|
|
202
|
+
|
|
203
|
+
#[test]
|
|
204
|
+
#[expected_failure]
|
|
205
|
+
fun test_reactive_initiator_not_participant_aborts() {
|
|
206
|
+
let mut ctx = sui::tx_context::dummy();
|
|
207
|
+
let sender = ctx.sender();
|
|
208
|
+
|
|
209
|
+
let permit = make_permanent_permit(vector[@0xAAAA, @0xBBBB], &mut ctx);
|
|
210
|
+
let mut from = make_us(sender, &mut ctx);
|
|
211
|
+
let mut target = make_us(@0xBBBB, &mut ctx);
|
|
212
|
+
|
|
213
|
+
dapp_system::set_record_reactive<SceneKey, SceneKey>(
|
|
214
|
+
SceneKey {}, &permit, &mut from, &mut target,
|
|
215
|
+
key_for(b"hp"), fns(), u64_val(50), &mut ctx,
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
dapp_service::destroy_user_storage(from);
|
|
219
|
+
dapp_service::destroy_user_storage(target);
|
|
220
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ─── set_record_reactive: target not in scene ────────────────────────────────
|
|
224
|
+
|
|
225
|
+
#[test]
|
|
226
|
+
#[expected_failure]
|
|
227
|
+
fun test_reactive_target_not_participant_aborts() {
|
|
228
|
+
let mut ctx = sui::tx_context::dummy();
|
|
229
|
+
let sender = ctx.sender();
|
|
230
|
+
|
|
231
|
+
let permit = make_permanent_permit(vector[sender, @0xBBBB], &mut ctx);
|
|
232
|
+
let mut from = make_us(sender, &mut ctx);
|
|
233
|
+
let mut target = make_us(@0xCCCC, &mut ctx);
|
|
234
|
+
|
|
235
|
+
dapp_system::set_record_reactive<SceneKey, SceneKey>(
|
|
236
|
+
SceneKey {}, &permit, &mut from, &mut target,
|
|
237
|
+
key_for(b"hp"), fns(), u64_val(50), &mut ctx,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
dapp_service::destroy_user_storage(from);
|
|
241
|
+
dapp_service::destroy_user_storage(target);
|
|
242
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ─── set_record_reactive: expired scene ──────────────────────────────────────
|
|
246
|
+
|
|
247
|
+
#[test]
|
|
248
|
+
#[expected_failure]
|
|
249
|
+
fun test_reactive_expired_scene_aborts() {
|
|
250
|
+
let mut ctx = sui::tx_context::dummy();
|
|
251
|
+
let sender = ctx.sender();
|
|
252
|
+
|
|
253
|
+
let permit = make_permit(vector[sender, @0xBBBB], std::option::some(0), &mut ctx);
|
|
254
|
+
let mut from = make_us(sender, &mut ctx);
|
|
255
|
+
let mut target = make_us(@0xBBBB, &mut ctx);
|
|
256
|
+
|
|
257
|
+
dapp_system::set_record_reactive<SceneKey, SceneKey>(
|
|
258
|
+
SceneKey {}, &permit, &mut from, &mut target,
|
|
259
|
+
key_for(b"hp"), fns(), u64_val(50), &mut ctx,
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
dapp_service::destroy_user_storage(from);
|
|
263
|
+
dapp_service::destroy_user_storage(target);
|
|
264
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ─── set_field_reactive: happy path ──────────────────────────────────────────
|
|
268
|
+
|
|
269
|
+
#[test]
|
|
270
|
+
fun test_set_field_reactive_ok() {
|
|
271
|
+
let mut ctx = sui::tx_context::dummy();
|
|
272
|
+
let sender = ctx.sender();
|
|
273
|
+
|
|
274
|
+
let permit = make_permanent_permit(vector[sender, @0xDDDD], &mut ctx);
|
|
275
|
+
let mut from = make_us(sender, &mut ctx);
|
|
276
|
+
let mut target = make_us(@0xDDDD, &mut ctx);
|
|
277
|
+
|
|
278
|
+
dapp_system::set_record_reactive<SceneKey, SceneKey>(
|
|
279
|
+
SceneKey {}, &permit, &mut from, &mut target,
|
|
280
|
+
key_for(b"stats"), vector[b"hp", b"mp"], vector[to_bytes(&100u64), to_bytes(&50u64)], &mut ctx,
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
dapp_system::set_field_reactive<SceneKey, SceneKey>(
|
|
284
|
+
SceneKey {}, &permit, &mut from, &mut target,
|
|
285
|
+
key_for(b"stats"), b"hp", to_bytes(&80u64), &mut ctx,
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
assert!(dapp_service::write_count(&from) == 2, 0);
|
|
289
|
+
|
|
290
|
+
dapp_service::destroy_user_storage(from);
|
|
291
|
+
dapp_service::destroy_user_storage(target);
|
|
292
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ─── Invitation flow tests ─────────────────────────────────────────────────────
|
|
296
|
+
|
|
297
|
+
#[test]
|
|
298
|
+
fun test_accept_invitation_moves_invitee_to_participants() {
|
|
299
|
+
let alice = @0xA;
|
|
300
|
+
let bob = @0xB;
|
|
301
|
+
let ctx = &mut tx_context::new_from_hint(alice, 0, 10, 0, 0);
|
|
302
|
+
|
|
303
|
+
let mut permit = make_permit_with_invitations(
|
|
304
|
+
vector[alice, bob],
|
|
305
|
+
std::option::none(),
|
|
306
|
+
std::option::none(),
|
|
307
|
+
ctx,
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
assert!(!dapp_service::is_participant_in_scene_permit(&permit, alice), 0);
|
|
311
|
+
assert!(dapp_service::is_scene_invitee(dapp_service::scene_permit_meta(&permit), alice), 1);
|
|
312
|
+
|
|
313
|
+
let us_alice = make_us(alice, ctx);
|
|
314
|
+
dapp_system::accept_scene_permit_invitation<SceneKey, SceneKey>(SceneKey {}, &mut permit, &us_alice, ctx);
|
|
315
|
+
|
|
316
|
+
assert!(dapp_service::is_participant_in_scene_permit(&permit, alice), 2);
|
|
317
|
+
assert!(!dapp_service::is_scene_invitee(dapp_service::scene_permit_meta(&permit), alice), 3);
|
|
318
|
+
assert!(dapp_service::is_scene_invitee(dapp_service::scene_permit_meta(&permit), bob), 4);
|
|
319
|
+
assert!(!dapp_service::is_participant_in_scene_permit(&permit, bob), 5);
|
|
320
|
+
|
|
321
|
+
dapp_service::destroy_user_storage(us_alice);
|
|
322
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
#[test]
|
|
326
|
+
fun test_accept_invitation_with_expiry_in_window() {
|
|
327
|
+
let alice = @0xA;
|
|
328
|
+
let ctx = &mut tx_context::new_from_hint(alice, 0, 0, 0, 0);
|
|
329
|
+
|
|
330
|
+
let mut permit = make_permit_with_invitations(
|
|
331
|
+
vector[alice],
|
|
332
|
+
std::option::some(1_000),
|
|
333
|
+
std::option::none(),
|
|
334
|
+
ctx,
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
let us_alice = make_us(alice, ctx);
|
|
338
|
+
dapp_system::accept_scene_permit_invitation<SceneKey, SceneKey>(SceneKey {}, &mut permit, &us_alice, ctx);
|
|
339
|
+
assert!(dapp_service::is_participant_in_scene_permit(&permit, alice), 0);
|
|
340
|
+
|
|
341
|
+
dapp_service::destroy_user_storage(us_alice);
|
|
342
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
#[test]
|
|
346
|
+
#[expected_failure]
|
|
347
|
+
fun test_accept_invitation_expired_aborts() {
|
|
348
|
+
let alice = @0xA;
|
|
349
|
+
let ctx = &mut tx_context::new_from_hint(alice, 0, 0, 2_000, 0);
|
|
350
|
+
|
|
351
|
+
let mut permit = make_permit_with_invitations(
|
|
352
|
+
vector[alice],
|
|
353
|
+
std::option::some(1_000),
|
|
354
|
+
std::option::none(),
|
|
355
|
+
ctx,
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
let us_alice = make_us(alice, ctx);
|
|
359
|
+
dapp_system::accept_scene_permit_invitation<SceneKey, SceneKey>(SceneKey {}, &mut permit, &us_alice, ctx);
|
|
360
|
+
dapp_service::destroy_user_storage(us_alice);
|
|
361
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
#[test]
|
|
365
|
+
#[expected_failure]
|
|
366
|
+
fun test_accept_invitation_not_invited_aborts() {
|
|
367
|
+
let charlie = @0xC;
|
|
368
|
+
let ctx = &mut tx_context::new_from_hint(charlie, 0, 0, 0, 0);
|
|
369
|
+
|
|
370
|
+
let mut permit = make_permit_with_invitations(
|
|
371
|
+
vector[@0xA],
|
|
372
|
+
std::option::none(),
|
|
373
|
+
std::option::none(),
|
|
374
|
+
ctx,
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
let us_charlie = make_us(charlie, ctx);
|
|
378
|
+
dapp_system::accept_scene_permit_invitation<SceneKey, SceneKey>(SceneKey {}, &mut permit, &us_charlie, ctx);
|
|
379
|
+
dapp_service::destroy_user_storage(us_charlie);
|
|
380
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
#[test]
|
|
384
|
+
fun test_all_invitees_accept_flow() {
|
|
385
|
+
let alice = @0xA;
|
|
386
|
+
let bob = @0xB;
|
|
387
|
+
|
|
388
|
+
let ctx_a = &mut tx_context::new_from_hint(alice, 0, 0, 0, 0);
|
|
389
|
+
let mut permit = make_permit_with_invitations(
|
|
390
|
+
vector[alice, bob],
|
|
391
|
+
std::option::none(),
|
|
392
|
+
std::option::none(),
|
|
393
|
+
ctx_a,
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
let us_alice = make_us(alice, ctx_a);
|
|
397
|
+
dapp_system::accept_scene_permit_invitation<SceneKey, SceneKey>(SceneKey {}, &mut permit, &us_alice, ctx_a);
|
|
398
|
+
|
|
399
|
+
let ctx_b = &mut tx_context::new_from_hint(bob, 0, 0, 0, 0);
|
|
400
|
+
let us_bob = make_us(bob, ctx_b);
|
|
401
|
+
dapp_system::accept_scene_permit_invitation<SceneKey, SceneKey>(SceneKey {}, &mut permit, &us_bob, ctx_b);
|
|
402
|
+
|
|
403
|
+
assert!(dapp_service::is_participant_in_scene_permit(&permit, alice), 0);
|
|
404
|
+
assert!(dapp_service::is_participant_in_scene_permit(&permit, bob), 1);
|
|
405
|
+
assert!(dapp_service::scene_invitees(dapp_service::scene_permit_meta(&permit)).is_empty(), 2);
|
|
406
|
+
assert!(dapp_service::scene_participant_count(dapp_service::scene_permit_meta(&permit)) == 2, 3);
|
|
407
|
+
|
|
408
|
+
dapp_service::destroy_user_storage(us_alice);
|
|
409
|
+
dapp_service::destroy_user_storage(us_bob);
|
|
410
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
#[test]
|
|
414
|
+
#[expected_failure]
|
|
415
|
+
fun test_accept_invitation_twice_aborts() {
|
|
416
|
+
let alice = @0xA;
|
|
417
|
+
let ctx = &mut tx_context::new_from_hint(alice, 0, 0, 0, 0);
|
|
418
|
+
|
|
419
|
+
let mut permit = make_permit_with_invitations(
|
|
420
|
+
vector[alice],
|
|
421
|
+
std::option::none(),
|
|
422
|
+
std::option::none(),
|
|
423
|
+
ctx,
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
let us_alice = make_us(alice, ctx);
|
|
427
|
+
dapp_system::accept_scene_permit_invitation<SceneKey, SceneKey>(SceneKey {}, &mut permit, &us_alice, ctx);
|
|
428
|
+
dapp_system::accept_scene_permit_invitation<SceneKey, SceneKey>(SceneKey {}, &mut permit, &us_alice, ctx);
|
|
429
|
+
dapp_service::destroy_user_storage(us_alice);
|
|
430
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
#[test]
|
|
434
|
+
#[expected_failure]
|
|
435
|
+
fun test_accept_invitation_on_expired_scene_aborts() {
|
|
436
|
+
let alice = @0xA;
|
|
437
|
+
let ctx = &mut tx_context::new_from_hint(alice, 0, 0, 0, 0);
|
|
438
|
+
|
|
439
|
+
// scene expires_at = 0 → already expired at epoch_timestamp_ms = 0
|
|
440
|
+
let mut permit = make_permit_with_invitations(
|
|
441
|
+
vector[alice],
|
|
442
|
+
std::option::none(),
|
|
443
|
+
std::option::some(0u64),
|
|
444
|
+
ctx,
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
let us_alice = make_us(alice, ctx);
|
|
448
|
+
dapp_system::accept_scene_permit_invitation<SceneKey, SceneKey>(SceneKey {}, &mut permit, &us_alice, ctx);
|
|
449
|
+
dapp_service::destroy_user_storage(us_alice);
|
|
450
|
+
dapp_service::destroy_scene_permit_for_testing(permit);
|
|
451
|
+
}
|
|
452
|
+
|