Skip to content

Commit

Permalink
Add discord module & tests (#12)
Browse files Browse the repository at this point in the history
* Add discord module + tests

* Address PR comments

* remove nw member fn, non needed

* Add test only

* Integrate with coupons system

* we want coupons in (0,100] range

* keep track of how many updates have happened on addresses to invalidate old sigs

* Address audit comments

* add tst only

* Fix revision for dep

* migrate to move2024

* Some more cleanups / simplification

* Minimize logic, remove table

* nit

* Fix discord mapping

* Nits

* Make payloads even more strict with a custom separator

* Adds e2e testing properly

* final minor adjustments (tie address setting to sender), add some PTBs + test them on testnet

* Minor changes + testing

* Remove non-needed readme

* Publish coupons on mainnet with burner

* Mainnet publish (correct), sanity check on signature, constants

* minor fixes
  • Loading branch information
manolisliolios authored Jun 17, 2024
1 parent 413db20 commit 964e224
Show file tree
Hide file tree
Showing 15 changed files with 999 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ tx-data.txt*
published.json
constants.sdk.json
dist
migration.patch
22 changes: 18 additions & 4 deletions packages/coupons/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "F6F1ED65982D6E0324AD5094A06FB092A7A055409AB912038DC0D2DA42E13854"
manifest_digest = "832599D4A2CAAA7AF930FB00A5FB78CA1EB7D00D25C8FBABD358233132DD1500"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
dependencies = [
{ name = "Sui" },
Expand All @@ -11,19 +11,19 @@ dependencies = [

[[move.package]]
name = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" }
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
name = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" }
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ name = "MoveStdlib" },
]

[[move.package]]
name = "suins"
source = { local = "../suins" }
source = { git = "https://github.com/mystenlabs/suins-contracts/", rev = "releases/mainnet/core/v3", subdir = "packages/suins" }

dependencies = [
{ name = "Sui" },
Expand All @@ -33,3 +33,17 @@ dependencies = [
compiler-version = "1.27.0"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x689a2d65a9666921e73ad4d59d13fee0d4be5df1ab5c0eeda8e0f7ebecb6f1b7"
latest-published-id = "0x689a2d65a9666921e73ad4d59d13fee0d4be5df1ab5c0eeda8e0f7ebecb6f1b7"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x6d14ca3049be747ec87166e6dce5d0d9a30f3b3c281c55d6e518958a236f8b97"
latest-published-id = "0x6d14ca3049be747ec87166e6dce5d0d9a30f3b3c281c55d6e518958a236f8b97"
published-version = "1"
8 changes: 5 additions & 3 deletions packages/coupons/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
name = "coupons"
version = "0.0.1"
edition = "2024.beta"
published-at="0x6d14ca3049be747ec87166e6dce5d0d9a30f3b3c281c55d6e518958a236f8b97"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet", override=true }
suins = { local = "../suins" }
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet", override=true }
# suins = { local = "../suins" }
suins = { git = "https://github.com/mystenlabs/suins-contracts/", subdir = "packages/suins", rev = "releases/mainnet/core/v3" }

[addresses]
coupons = "0x0"
coupons = "0x6d14ca3049be747ec87166e6dce5d0d9a30f3b3c281c55d6e518958a236f8b97"
6 changes: 3 additions & 3 deletions packages/coupons/sources/coupon_house.move
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module coupons::coupon_house {
};

suins::app_add_balance(CouponsApp {}, suins, payment.into_balance());
let registry = suins::app_registry_mut<CouponsApp, Registry>(CouponsApp {}, suins);
let registry: &mut Registry = suins::app_registry_mut(CouponsApp {}, suins);
registry.add_record(domain, no_years, clock, ctx)
}

Expand Down Expand Up @@ -211,13 +211,13 @@ module coupons::coupon_house {
}

/// Check if an application is authorized to access protected features of the Coupon House.
public fun is_app_authorized<A: drop>(coupon_house: &CouponHouse): bool {
fun is_app_authorized<A: drop>(coupon_house: &CouponHouse): bool {
df::exists_(&coupon_house.storage, AppKey<A>{})
}

/// Assert that an application is authorized to access protected features of Coupon House.
/// Aborts with `EAppNotAuthorized` if not.
public fun assert_app_is_authorized<A: drop>(coupon_house: &CouponHouse) {
fun assert_app_is_authorized<A: drop>(coupon_house: &CouponHouse) {
assert!(coupon_house.is_app_authorized<A>(), EAppNotAuthorized);
}

Expand Down
22 changes: 12 additions & 10 deletions packages/coupons/tests/setup.move
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,33 @@ module coupons::setup {
public fun test_init(): Scenario {
let mut scenario_val = test_scenario::begin(ADMIN_ADDRESS);
let scenario = &mut scenario_val;
initialize_coupon_house(scenario);
scenario_val
}

public fun initialize_coupon_house(scenario: &mut Scenario) {
{
let mut suins = suins::init_for_testing(ctx(scenario));
let mut suins = suins::init_for_testing(scenario.ctx());
suins::authorize_app_for_testing<CouponsApp>(&mut suins);
suins::share_for_testing(suins);
let clock = clock::create_for_testing(ctx(scenario));
let clock = clock::create_for_testing(scenario.ctx());
clock::share_for_testing(clock);
};
{
scenario.next_tx(ADMIN_ADDRESS);

// get admin cap
let admin_cap = scenario.take_from_sender<AdminCap>();
let mut suins = scenario.take_shared<SuiNS>();
// initialize coupon data.
coupon_house::setup(&mut suins, &admin_cap, ctx(scenario));
registry::init_for_testing(&admin_cap, &mut suins, ctx(scenario));
coupon_house::setup(&mut suins, &admin_cap, scenario.ctx());
registry::init_for_testing(&admin_cap, &mut suins, scenario.ctx());
// authorize TestApp to CouponHouse.
coupon_house::authorize_app<TestApp>(&admin_cap, &mut suins);
test_scenario::return_to_sender(scenario, admin_cap);
test_scenario::return_shared(suins);
};
scenario_val
}


public fun admin(): address {
ADMIN_ADDRESS
}
Expand Down Expand Up @@ -191,7 +193,7 @@ module coupons::setup {
kind,
value,
rules::new_empty_rules(),
ctx(scenario)
scenario.ctx()
);
scenario.return_to_sender(cap);
test_scenario::return_shared(suins);
Expand Down Expand Up @@ -222,7 +224,7 @@ module coupons::setup {
clock.increment_for_testing(clock_value);
let mut suins = scenario.take_shared<SuiNS>();

let payment = coin::mint_for_testing<SUI>(amount, ctx(scenario));
let payment = coin::mint_for_testing<SUI>(amount, scenario.ctx());

let nft = coupon_house::register_with_coupon(
&mut suins,
Expand All @@ -231,7 +233,7 @@ module coupons::setup {
no_years,
payment,
&clock,
ctx(scenario)
scenario.ctx()
);

transfer::public_transfer(nft, user);
Expand Down
60 changes: 60 additions & 0 deletions packages/discord/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 0

dependencies = [
{ name = "Sui" },
{ name = "coupons" },
{ name = "suins" },
]
manifest_digest = "C488D0BD18C8290C46485B8528126369EF13493F2C62ECAC18F402AB22973B8F"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"

[[move.package]]
name = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
name = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ name = "MoveStdlib" },
]

[[move.package]]
name = "coupons"
source = { git = "https://github.com/mystenlabs/suins-contracts/", rev = "releases/mainnet/coupons/v1", subdir = "packages/coupons" }

dependencies = [
{ name = "Sui" },
{ name = "suins" },
]

[[move.package]]
name = "suins"
source = { git = "https://github.com/mystenlabs/suins-contracts/", rev = "releases/mainnet/core/v3", subdir = "packages/suins" }

dependencies = [
{ name = "Sui" },
]

[move.toolchain-version]
compiler-version = "1.27.0"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x8f01eb1378d53e62239f8cf4ca495c703eb346f35902cf5d7b7727cd6c0b39fc"
latest-published-id = "0x8f01eb1378d53e62239f8cf4ca495c703eb346f35902cf5d7b7727cd6c0b39fc"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x408d22066775f20e0c13617c1f157a110d9a5b0873b878692b78aba92b1a46e1"
latest-published-id = "0x408d22066775f20e0c13617c1f157a110d9a5b0873b878692b78aba92b1a46e1"
published-version = "1"
15 changes: 15 additions & 0 deletions packages/discord/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "discord"
version = "0.0.1"
edition = "2024.beta"
published-at="0x408d22066775f20e0c13617c1f157a110d9a5b0873b878692b78aba92b1a46e1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet", override=true }
# coupons = { local = "../coupons" }
# suins = { local = "../suins" }
suins = { git = "https://github.com/mystenlabs/suins-contracts/", subdir = "packages/suins", rev = "releases/mainnet/core/v3" }
coupons = { git = "https://github.com/mystenlabs/suins-contracts/", subdir = "packages/coupons", rev = "releases/mainnet/coupons/v1" }

[addresses]
discord = "0x408d22066775f20e0c13617c1f157a110d9a5b0873b878692b78aba92b1a46e1"
9 changes: 9 additions & 0 deletions packages/discord/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Discord package

A package that allows discord member loyalty for SuiNS


## Testnet


V1: `0x2351c4b276766b38dfffdece41e7e72e538ba6ce999a0acf582e93c21d7b880f`
Loading

0 comments on commit 964e224

Please sign in to comment.