diff --git a/Cargo.lock b/Cargo.lock index 9bc8c76a3..262037ee0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4597,7 +4597,7 @@ dependencies = [ [[package]] name = "vending-minter-merkle-wl" -version = "3.3.0" +version = "3.4.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -4805,7 +4805,7 @@ dependencies = [ [[package]] name = "whitelist-mtree" -version = "3.3.0" +version = "3.4.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/contracts/minters/vending-minter-merkle-wl/schema/execute_msg.json b/contracts/minters/vending-minter-merkle-wl/schema/execute_msg.json index a6044d1ab..210ad1b75 100644 --- a/contracts/minters/vending-minter-merkle-wl/schema/execute_msg.json +++ b/contracts/minters/vending-minter-merkle-wl/schema/execute_msg.json @@ -10,6 +10,17 @@ "properties": { "mint": { "type": "object", + "properties": { + "proof_hashes": { + "type": [ + "array", + "null" + ], + "items": { + "type": "string" + } + } + }, "additionalProperties": false } }, diff --git a/contracts/minters/vending-minter-merkle-wl/src/contract.rs b/contracts/minters/vending-minter-merkle-wl/src/contract.rs index 5fd81b599..c8dd1d504 100644 --- a/contracts/minters/vending-minter-merkle-wl/src/contract.rs +++ b/contracts/minters/vending-minter-merkle-wl/src/contract.rs @@ -29,13 +29,13 @@ use sg_std::{StargazeMsgWrapper, GENESIS_MINT_START_TIME, NATIVE_DENOM}; use sg_whitelist::msg::{ ConfigResponse as WhitelistConfigResponse, HasMemberResponse, QueryMsg as WhitelistQueryMsg, }; -use whitelist_mtree::msg::QueryMsg as WhitelistMtreeQueryMsg; use sha2::{Digest, Sha256}; use shuffle::{fy::FisherYates, shuffler::Shuffler}; use std::convert::TryInto; use url::Url; use vending_factory::msg::{ParamsResponse, VendingMinterCreateMsg}; use vending_factory::state::VendingMinterParams; +use whitelist_mtree::msg::QueryMsg as WhitelistMtreeQueryMsg; pub type Response = cosmwasm_std::Response; pub type SubMsg = cosmwasm_std::SubMsg; @@ -489,7 +489,9 @@ pub fn execute_mint_sender( // If there is no active whitelist right now, check public mint // Check if after start_time - if is_public_mint(deps.as_ref(), &info, proof_hashes)? && (env.block.time < config.extension.start_time) { + if is_public_mint(deps.as_ref(), &info, proof_hashes)? + && (env.block.time < config.extension.start_time) + { return Err(ContractError::BeforeMintStartTime {}); } @@ -504,7 +506,11 @@ pub fn execute_mint_sender( // Check if a whitelist exists and not ended // Sender has to be whitelisted to mint -fn is_public_mint(deps: Deps, info: &MessageInfo, proof_hashes: Option>) -> Result { +fn is_public_mint( + deps: Deps, + info: &MessageInfo, + proof_hashes: Option>, +) -> Result { let config = CONFIG.load(deps.storage)?; // If there is no whitelist, there's only a public mint @@ -554,13 +560,10 @@ fn is_public_mint(deps: Deps, info: &MessageInfo, proof_hashes: Option bool { - wl_config_res.member_limit == 0 && - wl_config_res.num_members == 0 + wl_config_res.member_limit == 0 && wl_config_res.num_members == 0 } - pub fn execute_mint_to( deps: DepsMut, env: Env, diff --git a/contracts/minters/vending-minter-merkle-wl/src/msg.rs b/contracts/minters/vending-minter-merkle-wl/src/msg.rs index cdf95406c..9644543c3 100644 --- a/contracts/minters/vending-minter-merkle-wl/src/msg.rs +++ b/contracts/minters/vending-minter-merkle-wl/src/msg.rs @@ -11,7 +11,7 @@ pub struct InstantiateMsg { #[cw_serde] pub enum ExecuteMsg { Mint { - proof_hashes: Option> + proof_hashes: Option>, }, SetWhitelist { whitelist: String, diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/execute.json b/contracts/whitelists/whitelist-merkletree/schema/raw/execute.json deleted file mode 100644 index 48a24ca07..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/execute.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "ExecuteMsg", - "oneOf": [ - { - "type": "object", - "required": [ - "update_start_time" - ], - "properties": { - "update_start_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "update_end_time" - ], - "properties": { - "update_end_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "update_admins" - ], - "properties": { - "update_admins": { - "type": "object", - "required": [ - "admins" - ], - "properties": { - "admins": { - "type": "array", - "items": { - "type": "string" - } - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "freeze" - ], - "properties": { - "freeze": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - } - ], - "definitions": { - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/instantiate.json b/contracts/whitelists/whitelist-merkletree/schema/raw/instantiate.json deleted file mode 100644 index c1b60a34c..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/instantiate.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "InstantiateMsg", - "type": "object", - "required": [ - "admins", - "admins_mutable", - "end_time", - "merkle_root", - "mint_price", - "per_address_limit", - "start_time" - ], - "properties": { - "admins": { - "type": "array", - "items": { - "type": "string" - } - }, - "admins_mutable": { - "type": "boolean" - }, - "end_time": { - "$ref": "#/definitions/Timestamp" - }, - "merkle_root": { - "type": "string" - }, - "merkle_tree_uri": { - "type": [ - "string", - "null" - ] - }, - "mint_price": { - "$ref": "#/definitions/Coin" - }, - "per_address_limit": { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "start_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false, - "definitions": { - "Coin": { - "type": "object", - "required": [ - "amount", - "denom" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "denom": { - "type": "string" - } - } - }, - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/query.json b/contracts/whitelists/whitelist-merkletree/schema/raw/query.json deleted file mode 100644 index 216056198..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/query.json +++ /dev/null @@ -1,451 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "QueryMsg", - "oneOf": [ - { - "type": "object", - "required": [ - "has_started" - ], - "properties": { - "has_started": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "has_ended" - ], - "properties": { - "has_ended": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "is_active" - ], - "properties": { - "is_active": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "has_member" - ], - "properties": { - "has_member": { - "type": "object", - "required": [ - "member", - "proof_hashes" - ], - "properties": { - "member": { - "type": "string" - }, - "proof_hashes": { - "type": "array", - "items": { - "type": "string" - } - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "config" - ], - "properties": { - "config": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "admin_list" - ], - "properties": { - "admin_list": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "can_execute" - ], - "properties": { - "can_execute": { - "type": "object", - "required": [ - "msg", - "sender" - ], - "properties": { - "msg": { - "$ref": "#/definitions/CosmosMsg_for_Empty" - }, - "sender": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "merkle_root" - ], - "properties": { - "merkle_root": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "merkle_tree_u_r_i" - ], - "properties": { - "merkle_tree_u_r_i": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - } - ], - "definitions": { - "BankMsg": { - "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", - "oneOf": [ - { - "description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "send" - ], - "properties": { - "send": { - "type": "object", - "required": [ - "amount", - "to_address" - ], - "properties": { - "amount": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "to_address": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This will burn the given coins from the contract's account. There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. Important if a contract controls significant token supply that must be retired.", - "type": "object", - "required": [ - "burn" - ], - "properties": { - "burn": { - "type": "object", - "required": [ - "amount" - ], - "properties": { - "amount": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" - }, - "Coin": { - "type": "object", - "required": [ - "amount", - "denom" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "denom": { - "type": "string" - } - } - }, - "CosmosMsg_for_Empty": { - "oneOf": [ - { - "type": "object", - "required": [ - "bank" - ], - "properties": { - "bank": { - "$ref": "#/definitions/BankMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "custom" - ], - "properties": { - "custom": { - "$ref": "#/definitions/Empty" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "wasm" - ], - "properties": { - "wasm": { - "$ref": "#/definitions/WasmMsg" - } - }, - "additionalProperties": false - } - ] - }, - "Empty": { - "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", - "type": "object" - }, - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - }, - "WasmMsg": { - "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", - "oneOf": [ - { - "description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "execute" - ], - "properties": { - "execute": { - "type": "object", - "required": [ - "contract_addr", - "funds", - "msg" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "msg": { - "description": "msg is the json-encoded ExecuteMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "instantiate" - ], - "properties": { - "instantiate": { - "type": "object", - "required": [ - "code_id", - "funds", - "label", - "msg" - ], - "properties": { - "admin": { - "type": [ - "string", - "null" - ] - }, - "code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "label": { - "description": "A human-readbale label for the contract", - "type": "string" - }, - "msg": { - "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "migrate" - ], - "properties": { - "migrate": { - "type": "object", - "required": [ - "contract_addr", - "msg", - "new_code_id" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "msg": { - "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - }, - "new_code_id": { - "description": "the code_id of the new logic to place in the given contract", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract.", - "type": "object", - "required": [ - "update_admin" - ], - "properties": { - "update_admin": { - "type": "object", - "required": [ - "admin", - "contract_addr" - ], - "properties": { - "admin": { - "type": "string" - }, - "contract_addr": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract.", - "type": "object", - "required": [ - "clear_admin" - ], - "properties": { - "clear_admin": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - } - } -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_admin_list.json b/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_admin_list.json deleted file mode 100644 index 3b04e955c..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_admin_list.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "AdminListResponse", - "type": "object", - "required": [ - "admins", - "mutable" - ], - "properties": { - "admins": { - "type": "array", - "items": { - "type": "string" - } - }, - "mutable": { - "type": "boolean" - } - }, - "additionalProperties": false -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_can_execute.json b/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_can_execute.json deleted file mode 100644 index e2ed10214..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_can_execute.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "CanExecuteResponse", - "type": "object", - "required": [ - "can_execute" - ], - "properties": { - "can_execute": { - "type": "boolean" - } - }, - "additionalProperties": false -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_config.json b/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_config.json deleted file mode 100644 index e96c30e53..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_config.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "ConfigResponse", - "type": "object", - "required": [ - "end_time", - "is_active", - "member_limit", - "mint_price", - "num_members", - "per_address_limit", - "start_time" - ], - "properties": { - "end_time": { - "$ref": "#/definitions/Timestamp" - }, - "is_active": { - "type": "boolean" - }, - "member_limit": { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "mint_price": { - "$ref": "#/definitions/Coin" - }, - "num_members": { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "per_address_limit": { - "type": "integer", - "format": "uint32", - "minimum": 0.0 - }, - "start_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false, - "definitions": { - "Coin": { - "type": "object", - "required": [ - "amount", - "denom" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "denom": { - "type": "string" - } - } - }, - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_has_ended.json b/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_has_ended.json deleted file mode 100644 index 6e207ab48..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_has_ended.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "HasEndedResponse", - "type": "object", - "required": [ - "has_ended" - ], - "properties": { - "has_ended": { - "type": "boolean" - } - }, - "additionalProperties": false -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_has_member.json b/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_has_member.json deleted file mode 100644 index 8e203003b..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_has_member.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "HasMemberResponse", - "type": "object", - "required": [ - "has_member" - ], - "properties": { - "has_member": { - "type": "boolean" - } - }, - "additionalProperties": false -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_has_started.json b/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_has_started.json deleted file mode 100644 index 25614f8d8..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_has_started.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "HasStartedResponse", - "type": "object", - "required": [ - "has_started" - ], - "properties": { - "has_started": { - "type": "boolean" - } - }, - "additionalProperties": false -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_is_active.json b/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_is_active.json deleted file mode 100644 index 2dc928c41..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_is_active.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "IsActiveResponse", - "type": "object", - "required": [ - "is_active" - ], - "properties": { - "is_active": { - "type": "boolean" - } - }, - "additionalProperties": false -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_merkle_root.json b/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_merkle_root.json deleted file mode 100644 index fad931f91..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_merkle_root.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "MerkleRootResponse", - "type": "object", - "required": [ - "merkle_root" - ], - "properties": { - "merkle_root": { - "type": "string" - } - }, - "additionalProperties": false -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_merkle_tree_u_r_i.json b/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_merkle_tree_u_r_i.json deleted file mode 100644 index a6991d43f..000000000 --- a/contracts/whitelists/whitelist-merkletree/schema/raw/response_to_merkle_tree_u_r_i.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "MerkleTreeURIResponse", - "type": "object", - "properties": { - "merkle_tree_uri": { - "type": [ - "string", - "null" - ] - } - }, - "additionalProperties": false -} diff --git a/contracts/whitelists/whitelist-merkletree/schema/whitelist-mtree.json b/contracts/whitelists/whitelist-merkletree/schema/whitelist-mtree.json index 634cb4c63..2c8866aee 100644 --- a/contracts/whitelists/whitelist-merkletree/schema/whitelist-mtree.json +++ b/contracts/whitelists/whitelist-merkletree/schema/whitelist-mtree.json @@ -1,6 +1,6 @@ { "contract_name": "whitelist-mtree", - "contract_version": "3.1.0", + "contract_version": "3.4.0", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", @@ -513,7 +513,7 @@ } }, "label": { - "description": "A human-readbale label for the contract", + "description": "A human-readable label for the contract.\n\nValid values should: - not be empty - not be bigger than 128 bytes (or some chain-specific limit) - not start / end with whitespace", "type": "string" }, "msg": { diff --git a/contracts/whitelists/whitelist-merkletree/src/contract.rs b/contracts/whitelists/whitelist-merkletree/src/contract.rs index a85d65d59..ce8d76944 100644 --- a/contracts/whitelists/whitelist-merkletree/src/contract.rs +++ b/contracts/whitelists/whitelist-merkletree/src/contract.rs @@ -2,24 +2,25 @@ use crate::admin::{ can_execute, execute_freeze, execute_update_admins, query_admin_list, query_can_execute, }; use crate::error::ContractError; -use crate::helpers::crypto::{verify_merkle_root, valid_hash_string, string_to_byte_slice}; +use crate::helpers::crypto::{string_to_byte_slice, valid_hash_string, verify_merkle_root}; use crate::helpers::utils::verify_tree_uri; use crate::helpers::validators::map_validate; use crate::msg::{ - ConfigResponse, ExecuteMsg, HasEndedResponse, HasMemberResponse, - HasStartedResponse, InstantiateMsg, IsActiveResponse, QueryMsg, MerkleRootResponse, MerkleTreeURIResponse, + ConfigResponse, ExecuteMsg, HasEndedResponse, HasMemberResponse, HasStartedResponse, + InstantiateMsg, IsActiveResponse, MerkleRootResponse, MerkleTreeURIResponse, QueryMsg, }; use crate::state::{AdminList, Config, ADMIN_LIST, CONFIG, MERKLE_ROOT, MERKLE_TREE_URI}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, StdResult, StdError, Timestamp}; +use cosmwasm_std::{ + to_binary, Binary, Deps, DepsMut, Env, MessageInfo, StdError, StdResult, Timestamp, +}; use cw2::set_contract_version; -use sg_std::{Response, GENESIS_MINT_START_TIME, NATIVE_DENOM}; use cw_utils::nonpayable; +use sg_std::{Response, GENESIS_MINT_START_TIME, NATIVE_DENOM}; use rs_merkle::{algorithms::Sha256, Hasher}; - // version info for migration info const CONTRACT_NAME: &str = "crates.io:whitelist-merkletree"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -28,7 +29,6 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const PRICE_PER_1000_MEMBERS: u128 = 100_000_000; pub const MIN_MINT_PRICE: u128 = 0; - #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -67,7 +67,6 @@ pub fn instantiate( )); } - let config = Config { start_time: msg.start_time, end_time: msg.end_time, @@ -75,7 +74,6 @@ pub fn instantiate( per_address_limit: msg.per_address_limit, }; - let admin_config = AdminList { admins: map_validate(deps.api, &msg.admins)?, mutable: msg.admins_mutable, @@ -84,23 +82,23 @@ pub fn instantiate( MERKLE_ROOT.save(deps.storage, &msg.merkle_root)?; ADMIN_LIST.save(deps.storage, &admin_config)?; CONFIG.save(deps.storage, &config)?; - - let tree_url = msg.merkle_tree_uri.unwrap_or(String::default()); + + let tree_url = msg.merkle_tree_uri.unwrap_or_default(); let mut attrs = Vec::with_capacity(6); - + attrs.push(("action", "update_merkle_tree")); attrs.push(("merkle_root", &msg.merkle_root)); attrs.push(("contract_name", CONTRACT_NAME)); attrs.push(("contract_version", CONTRACT_VERSION)); - if tree_url.len() > 0 { attrs.push(("merkle_tree_uri", &tree_url)); } + if !tree_url.is_empty() { + attrs.push(("merkle_tree_uri", &tree_url)); + } attrs.push(("sender", info.sender.as_str())); Ok(Response::new().add_attributes(attrs)) - } - #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( deps: DepsMut, @@ -134,18 +132,18 @@ pub fn execute_update_merkle_tree( MERKLE_ROOT.save(deps.storage, &merkle_root)?; - let mut attrs = Vec::with_capacity(4); - + attrs.push(("action", String::from("update_merkle_tree"))); attrs.push(("merkle_root", merkle_root)); - if let Some(uri) = merkle_tree_uri { attrs.push(("merkle_tree_uri", uri)); } + if let Some(uri) = merkle_tree_uri { + attrs.push(("merkle_tree_uri", uri)); + } attrs.push(("sender", info.sender.to_string())); Ok(Response::new().add_attributes(attrs)) } - pub fn execute_update_start_time( deps: DepsMut, env: Env, @@ -179,8 +177,6 @@ pub fn execute_update_start_time( .add_attribute("sender", info.sender)) } - - pub fn execute_update_end_time( deps: DepsMut, env: Env, @@ -206,21 +202,21 @@ pub fn execute_update_end_time( .add_attribute("sender", info.sender)) } - - - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::HasStarted {} => to_binary(&query_has_started(deps, env)?), QueryMsg::HasEnded {} => to_binary(&query_has_ended(deps, env)?), QueryMsg::IsActive {} => to_binary(&query_is_active(deps, env)?), - QueryMsg::HasMember { member , proof_hashes} => to_binary(&query_has_member(deps, member, proof_hashes)?), + QueryMsg::HasMember { + member, + proof_hashes, + } => to_binary(&query_has_member(deps, member, proof_hashes)?), QueryMsg::Config {} => to_binary(&query_config(deps, env)?), QueryMsg::AdminList {} => to_binary(&query_admin_list(deps)?), QueryMsg::CanExecute { sender, .. } => to_binary(&query_can_execute(deps, &sender)?), QueryMsg::MerkleRoot {} => to_binary(&query_merkle_root(deps)?), - QueryMsg::MerkleTreeURI {} => to_binary(&query_merkle_tree_uri(deps)?) + QueryMsg::MerkleTreeURI {} => to_binary(&query_merkle_tree_uri(deps)?), } } @@ -245,36 +241,30 @@ fn query_is_active(deps: Deps, env: Env) -> StdResult { }) } - pub fn query_has_member( - deps: Deps, + deps: Deps, member: String, proof_hashes: Vec, ) -> StdResult { - deps.api.addr_validate(&member)?; let merkle_root = MERKLE_ROOT.load(deps.storage)?; let member_init_hash_slice = Sha256::hash(member.as_bytes()); - let final_hash = proof_hashes - .into_iter() - .try_fold(member_init_hash_slice, - |accum_hash_slice, new_proof_hashstring| { - valid_hash_string(&new_proof_hashstring)?; - - let mut hashe_slices = [ - accum_hash_slice, - string_to_byte_slice(&new_proof_hashstring)? - ]; - hashe_slices.sort_unstable(); - - Sha256::hash(&hashe_slices.concat()) - .try_into() - .map_err(|_| StdError::GenericErr { msg: "Error parsing merkle proof".to_string() }) - }); + let final_hash = proof_hashes.into_iter().try_fold( + member_init_hash_slice, + |accum_hash_slice, new_proof_hashstring| { + valid_hash_string(&new_proof_hashstring)?; + let mut hashe_slices = [ + accum_hash_slice, + string_to_byte_slice(&new_proof_hashstring)?, + ]; + hashe_slices.sort_unstable(); + Result::<[u8; 32], StdError>::Ok(Sha256::hash(&hashe_slices.concat())) + }, + ); if final_hash.is_err() { return Err(cosmwasm_std::StdError::GenericErr { @@ -282,8 +272,9 @@ pub fn query_has_member( }); } - return Ok(HasMemberResponse { has_member: merkle_root == hex::encode(final_hash.unwrap()) }); - + Ok(HasMemberResponse { + has_member: merkle_root == hex::encode(final_hash.unwrap()), + }) } pub fn query_config(deps: Deps, env: Env) -> StdResult { @@ -300,13 +291,13 @@ pub fn query_config(deps: Deps, env: Env) -> StdResult { } pub fn query_merkle_root(deps: Deps) -> StdResult { - Ok(MerkleRootResponse { - merkle_root: MERKLE_ROOT.load(deps.storage)? + Ok(MerkleRootResponse { + merkle_root: MERKLE_ROOT.load(deps.storage)?, }) } pub fn query_merkle_tree_uri(deps: Deps) -> StdResult { - Ok(MerkleTreeURIResponse { - merkle_tree_uri: MERKLE_TREE_URI.may_load(deps.storage)? + Ok(MerkleTreeURIResponse { + merkle_tree_uri: MERKLE_TREE_URI.may_load(deps.storage)?, }) -} \ No newline at end of file +} diff --git a/contracts/whitelists/whitelist-merkletree/src/helpers.rs b/contracts/whitelists/whitelist-merkletree/src/helpers.rs index 90ecbaac7..8009d09df 100644 --- a/contracts/whitelists/whitelist-merkletree/src/helpers.rs +++ b/contracts/whitelists/whitelist-merkletree/src/helpers.rs @@ -1,4 +1,4 @@ -pub mod interface; -pub mod validators; pub mod crypto; +pub mod interface; pub mod utils; +pub mod validators; diff --git a/contracts/whitelists/whitelist-merkletree/src/helpers/crypto.rs b/contracts/whitelists/whitelist-merkletree/src/helpers/crypto.rs index a7e65c34f..b76747b28 100644 --- a/contracts/whitelists/whitelist-merkletree/src/helpers/crypto.rs +++ b/contracts/whitelists/whitelist-merkletree/src/helpers/crypto.rs @@ -1,9 +1,11 @@ -use cosmwasm_std::{HexBinary, StdResult, StdError}; +use cosmwasm_std::{HexBinary, StdError, StdResult}; pub fn valid_hash_string(hash_string: &String) -> StdResult<()> { let hex_res = HexBinary::from_hex(hash_string.as_str()); if hex_res.is_err() { - return Err(cosmwasm_std::StdError::InvalidHex { msg: hash_string.to_string() }); + return Err(cosmwasm_std::StdError::InvalidHex { + msg: hash_string.to_string(), + }); } let hex_binary = hex_res.unwrap(); @@ -11,7 +13,10 @@ pub fn valid_hash_string(hash_string: &String) -> StdResult<()> { let decoded = hex_binary.to_array::<32>(); if decoded.is_err() { - return Err(cosmwasm_std::StdError::InvalidDataSize { expected: 32, actual: hex_binary.len() as u64 }) + return Err(cosmwasm_std::StdError::InvalidDataSize { + expected: 32, + actual: hex_binary.len() as u64, + }); } Ok(()) } @@ -22,7 +27,8 @@ pub fn verify_merkle_root(merkle_root: &String) -> StdResult<()> { pub fn string_to_byte_slice(string: &String) -> StdResult<[u8; 32]> { let mut byte_slice = [0; 32]; - hex::decode_to_slice(string, &mut byte_slice) - .map_err(|_| StdError::GenericErr { msg: "Couldn't decode hash string".to_string() })?; + hex::decode_to_slice(string, &mut byte_slice).map_err(|_| StdError::GenericErr { + msg: "Couldn't decode hash string".to_string(), + })?; Ok(byte_slice) } diff --git a/contracts/whitelists/whitelist-merkletree/src/helpers/utils.rs b/contracts/whitelists/whitelist-merkletree/src/helpers/utils.rs index a6619adb5..94771e472 100644 --- a/contracts/whitelists/whitelist-merkletree/src/helpers/utils.rs +++ b/contracts/whitelists/whitelist-merkletree/src/helpers/utils.rs @@ -1,14 +1,14 @@ use cosmwasm_std::StdResult; use url::Url; -pub fn verify_tree_uri( - tree_uri: &Option -) -> StdResult<()> { +pub fn verify_tree_uri(tree_uri: &Option) -> StdResult<()> { if tree_uri.is_some() { - let res = Url::parse(&tree_uri.as_ref().unwrap()); + let res = Url::parse(tree_uri.as_ref().unwrap()); if res.is_err() { - return Err(cosmwasm_std::StdError::GenericErr { msg: "Invalid tree uri".to_string() }); + return Err(cosmwasm_std::StdError::GenericErr { + msg: "Invalid tree uri".to_string(), + }); } } Ok(()) -} \ No newline at end of file +} diff --git a/contracts/whitelists/whitelist-merkletree/src/msg.rs b/contracts/whitelists/whitelist-merkletree/src/msg.rs index b995a3be6..f31680b00 100644 --- a/contracts/whitelists/whitelist-merkletree/src/msg.rs +++ b/contracts/whitelists/whitelist-merkletree/src/msg.rs @@ -21,7 +21,6 @@ pub struct InstantiateMsg { pub admins_mutable: bool, } - #[cw_serde] pub enum ExecuteMsg { UpdateStartTime(Timestamp), @@ -56,7 +55,10 @@ pub enum QueryMsg { #[returns(IsActiveResponse)] IsActive {}, #[returns(HasMemberResponse)] - HasMember { member: String, proof_hashes: Vec }, + HasMember { + member: String, + proof_hashes: Vec, + }, #[returns(ConfigResponse)] Config {}, #[returns(AdminListResponse)] @@ -69,16 +71,14 @@ pub enum QueryMsg { #[returns(MerkleRootResponse)] MerkleRoot {}, #[returns(MerkleTreeURIResponse)] - MerkleTreeURI {} + MerkleTreeURI {}, } - #[cw_serde] pub struct HasMemberResponse { pub has_member: bool, } - #[cw_serde] pub struct HasEndedResponse { pub has_ended: bool, @@ -99,7 +99,6 @@ pub struct MintPriceResponse { pub mint_price: Coin, } - #[cw_serde] pub struct ConfigResponse { pub num_members: u32, @@ -111,7 +110,6 @@ pub struct ConfigResponse { pub is_active: bool, } - #[cw_serde] pub struct MerkleRootResponse { pub merkle_root: String, diff --git a/contracts/whitelists/whitelist-merkletree/src/tests.rs b/contracts/whitelists/whitelist-merkletree/src/tests.rs index 87d3d2733..331bda8f8 100644 --- a/contracts/whitelists/whitelist-merkletree/src/tests.rs +++ b/contracts/whitelists/whitelist-merkletree/src/tests.rs @@ -1,3 +1,3 @@ -pub mod unit_tests; +pub mod hasher; pub mod test_helpers; -pub mod hasher; \ No newline at end of file +pub mod unit_tests; diff --git a/contracts/whitelists/whitelist-merkletree/src/tests/hasher.rs b/contracts/whitelists/whitelist-merkletree/src/tests/hasher.rs index 85669e387..646f35bc4 100644 --- a/contracts/whitelists/whitelist-merkletree/src/tests/hasher.rs +++ b/contracts/whitelists/whitelist-merkletree/src/tests/hasher.rs @@ -9,11 +9,9 @@ impl Hasher for SortingSha256Hasher { type Hash = [u8; 32]; fn concat_and_hash(left: &Self::Hash, right: Option<&Self::Hash>) -> Self::Hash { - match right { Some(right_node) => { - - let mut both = vec![left, right_node]; + let mut both = [left, right_node]; both.sort_unstable(); // TODO: Optimize this @@ -33,4 +31,4 @@ impl Hasher for SortingSha256Hasher { fn hash_size() -> usize { Sha256::hash_size() } -} \ No newline at end of file +} diff --git a/contracts/whitelists/whitelist-merkletree/src/tests/test_helpers.rs b/contracts/whitelists/whitelist-merkletree/src/tests/test_helpers.rs index 8321aac44..24fde4084 100644 --- a/contracts/whitelists/whitelist-merkletree/src/tests/test_helpers.rs +++ b/contracts/whitelists/whitelist-merkletree/src/tests/test_helpers.rs @@ -1,10 +1,8 @@ +use rs_merkle::{algorithms::Sha256, Hasher, MerkleTree}; use std::{fs::File, io::Read}; -use rs_merkle::{MerkleTree, algorithms::Sha256, Hasher}; use super::hasher::SortingSha256Hasher; - - fn text_from_file(path: &str) -> String { let mut file = File::open(path).unwrap(); let mut data = String::new(); @@ -12,8 +10,7 @@ fn text_from_file(path: &str) -> String { data } - -pub fn hash_and_build_tree(serialized: &Vec) -> MerkleTree:: { +pub fn hash_and_build_tree(serialized: &[String]) -> MerkleTree { let leaves: Vec<[u8; 32]> = serialized .iter() .map(|x| Sha256::hash(x.as_bytes())) @@ -22,11 +19,11 @@ pub fn hash_and_build_tree(serialized: &Vec) -> MerkleTree::::from_leaves(&leaves) } -pub fn tree_from_file(path: &str) -> MerkleTree:: { +pub fn tree_from_file(path: &str) -> MerkleTree { let data = text_from_file(path); let serialized: Vec = data - .split("\n") + .split('\n') .map(|x| x.to_string()) .filter(|s| !s.is_empty() && s.len() > 1) .collect(); @@ -34,7 +31,7 @@ pub fn tree_from_file(path: &str) -> MerkleTree:: { hash_and_build_tree(&serialized) } -pub fn get_merkle_tree_simple(path_prefix: Option) -> MerkleTree:: { +pub fn get_merkle_tree_simple(path_prefix: Option) -> MerkleTree { let path = path_prefix.unwrap_or_default() + "src/tests/data/whitelist_simple.txt"; tree_from_file(path.as_str()) } @@ -49,7 +46,7 @@ pub fn get_merkle_tree_large() -> MerkleTree { let data = text_from_file(path); let mut serialized: Vec = data - .split("\n") + .split('\n') .map(|x| x.to_string()) .filter(|s| !s.is_empty() && s.len() > 1) .collect(); @@ -59,4 +56,4 @@ pub fn get_merkle_tree_large() -> MerkleTree { } hash_and_build_tree(&serialized) -} \ No newline at end of file +} diff --git a/contracts/whitelists/whitelist-merkletree/src/tests/unit_tests.rs b/contracts/whitelists/whitelist-merkletree/src/tests/unit_tests.rs index 0469824dc..c9a42d063 100644 --- a/contracts/whitelists/whitelist-merkletree/src/tests/unit_tests.rs +++ b/contracts/whitelists/whitelist-merkletree/src/tests/unit_tests.rs @@ -1,29 +1,30 @@ #[cfg(test)] mod tests { - use std::vec; use crate::{ - msg::{InstantiateMsg, ExecuteMsg}, - contract::{instantiate, execute, query_config, query_has_member}, - tests::test_helpers::get_merkle_tree_simple + contract::{execute, instantiate, query_config, query_has_member}, + msg::{ExecuteMsg, InstantiateMsg}, + tests::test_helpers::get_merkle_tree_simple, }; + use std::vec; use cosmwasm_std::{ coin, - testing::{mock_dependencies, mock_env, mock_info}, Timestamp, DepsMut, Env, BlockInfo, + testing::{mock_dependencies, mock_env, mock_info}, + BlockInfo, DepsMut, Env, Timestamp, }; - use sg_std::{NATIVE_DENOM, GENESIS_MINT_START_TIME}; + use sg_std::{GENESIS_MINT_START_TIME, NATIVE_DENOM}; const ADMIN: &str = "admin"; const UNIT_AMOUNT: u128 = 100_000_000; const GENESIS_START_TIME: Timestamp = Timestamp::from_nanos(GENESIS_MINT_START_TIME); const END_TIME: Timestamp = Timestamp::from_nanos(GENESIS_MINT_START_TIME + 1000); - const MERKLE_ROOT: &str = "5ab281bca33c9819e0daa0708d20ff8a25e65de7d1f6659dbdeb1d2050652b80"; - const NON_HEX_MERKLE_ROOT: &str = "5zb281bca33c9819e0daa0708d20ff8a25e65de7d1f6659dbdeb1d2050652b80"; - const NON_32BYTES_MERKLE_ROOT: &str = "5ab281bca33c9819e0daa0708d20ff8a25e65de7d1f6659dbdeb1d2050652b80ab"; - + const NON_HEX_MERKLE_ROOT: &str = + "5zb281bca33c9819e0daa0708d20ff8a25e65de7d1f6659dbdeb1d2050652b80"; + const NON_32BYTES_MERKLE_ROOT: &str = + "5ab281bca33c9819e0daa0708d20ff8a25e65de7d1f6659dbdeb1d2050652b80ab"; fn setup_contract(deps: DepsMut, merkle_root: Option) { let msg = InstantiateMsg { @@ -40,17 +41,16 @@ mod tests { let res = instantiate(deps, mock_env(), info, msg).unwrap(); assert_eq!(0, res.messages.len()); assert_eq!(5, res.attributes.len()); - } fn custom_mock_env() -> Env { - Env { + Env { block: BlockInfo { height: 55_555, time: GENESIS_START_TIME.plus_nanos(100), chain_id: "stargaze-1".to_string(), }, - ..mock_env() + ..mock_env() } } @@ -66,7 +66,6 @@ mod tests { let env = custom_mock_env(); let invalid_msgs: Vec = vec![ - // invalid merkle root (non hex) InstantiateMsg { merkle_root: NON_HEX_MERKLE_ROOT.to_string(), @@ -78,7 +77,6 @@ mod tests { admins: vec![ADMIN.to_string()], admins_mutable: false, }, - // invalid merkle root (non 32 bytes) InstantiateMsg { merkle_root: NON_32BYTES_MERKLE_ROOT.to_string(), @@ -90,7 +88,6 @@ mod tests { admins: vec![ADMIN.to_string()], admins_mutable: false, }, - // invalid mint price denom InstantiateMsg { merkle_root: MERKLE_ROOT.to_string(), @@ -102,7 +99,6 @@ mod tests { admins: vec![ADMIN.to_string()], admins_mutable: false, }, - // invalid admin address (MockApi only) (too short) InstantiateMsg { merkle_root: MERKLE_ROOT.to_string(), @@ -114,7 +110,6 @@ mod tests { admins: vec!["A".to_string()], admins_mutable: false, }, - // invalid start time (after end time) InstantiateMsg { merkle_root: MERKLE_ROOT.to_string(), @@ -126,7 +121,6 @@ mod tests { admins: vec![ADMIN.to_string()], admins_mutable: false, }, - // invalid start time (before genesis mint start time) InstantiateMsg { merkle_root: MERKLE_ROOT.to_string(), @@ -138,7 +132,6 @@ mod tests { admins: vec![ADMIN.to_string()], admins_mutable: false, }, - // invalid start time (before current block time) InstantiateMsg { merkle_root: MERKLE_ROOT.to_string(), @@ -150,7 +143,6 @@ mod tests { admins: vec![ADMIN.to_string()], admins_mutable: false, }, - ]; let info = mock_info(ADMIN, &[]); @@ -160,8 +152,6 @@ mod tests { } } - - #[test] fn update_start_time() { let mut deps = mock_dependencies(); @@ -199,11 +189,11 @@ mod tests { setup_contract(deps.as_mut(), root.clone()); - let proof = tree.proof(&vec![0]); + let proof = tree.proof(&[0]); let hash_strings = proof.proof_hashes_hex(); let user = mock_info("stars1ye63jpm474yfrq02nyplrspyw75y82tptsls9t", &[]); - let res = query_has_member(deps.as_ref(), user.sender.to_string(), hash_strings).unwrap(); + let res = query_has_member(deps.as_ref(), user.sender.to_string(), hash_strings).unwrap(); assert!(res.has_member); let user = mock_info("stars130dxx3nr2ste4fwsum57k3en60wqd76m9pvpsy", &[]); @@ -222,7 +212,6 @@ mod tests { let res = query_has_member(deps.as_ref(), user.sender.to_string(), proof).unwrap(); assert!(res.has_member); - // mismatched proof let user = mock_info("stars1ye63jpm474yfrq02nyplrspyw75y82tptsls9t", &[]); let proof = vec![ @@ -237,5 +226,4 @@ mod tests { let proof = vec!["x".to_string(), "x".to_string()]; let _ = query_has_member(deps.as_ref(), user.sender.to_string(), proof).unwrap_err(); } - -} \ No newline at end of file +} diff --git a/test-suite/src/common_setup.rs b/test-suite/src/common_setup.rs index 4f82d1ce0..cc10d8105 100644 --- a/test-suite/src/common_setup.rs +++ b/test-suite/src/common_setup.rs @@ -4,6 +4,6 @@ pub mod helpers; pub mod msg; pub mod setup_accounts_and_block; pub mod setup_collection_whitelist; -pub mod setup_whitelist_merkletree; pub mod setup_minter; +pub mod setup_whitelist_merkletree; pub mod templates; diff --git a/test-suite/src/common_setup/contract_boxes.rs b/test-suite/src/common_setup/contract_boxes.rs index 2f5be14a3..65a9fd3d0 100644 --- a/test-suite/src/common_setup/contract_boxes.rs +++ b/test-suite/src/common_setup/contract_boxes.rs @@ -64,7 +64,6 @@ pub fn contract_collection_whitelist() -> Box> Box::new(contract) } - pub fn contract_open_edition_minter() -> Box> { let contract = ContractWrapper::new( open_edition_minter::contract::execute, @@ -148,4 +147,4 @@ pub fn contract_whitelist_merkletree() -> Box> whitelist_mtree::contract::query, ); Box::new(contract) -} \ No newline at end of file +} diff --git a/test-suite/src/common_setup/setup_whitelist_merkletree.rs b/test-suite/src/common_setup/setup_whitelist_merkletree.rs index 09ccc77df..1b1ed4766 100644 --- a/test-suite/src/common_setup/setup_whitelist_merkletree.rs +++ b/test-suite/src/common_setup/setup_whitelist_merkletree.rs @@ -14,7 +14,7 @@ pub fn setup_whitelist_mtree_contract( creator: &Addr, whitelist_code_id: Option, denom: Option<&str>, - merkle_root: String + merkle_root: String, ) -> Addr { let whitelist_code_id = match whitelist_code_id { Some(value) => value, @@ -25,7 +25,6 @@ pub fn setup_whitelist_mtree_contract( None => NATIVE_DENOM, }; - let msg = WhitelistInstantiateMsg { start_time: Timestamp::from_nanos(GENESIS_MINT_START_TIME + 100), end_time: Timestamp::from_nanos(GENESIS_MINT_START_TIME + 10_000_000), @@ -34,7 +33,7 @@ pub fn setup_whitelist_mtree_contract( admins: vec![creator.to_string()], admins_mutable: true, merkle_root, - merkle_tree_uri: None + merkle_tree_uri: None, }; router .instantiate_contract( diff --git a/test-suite/src/whitelist_merkletree.rs b/test-suite/src/whitelist_merkletree.rs index b90ccf403..14f00389d 100644 --- a/test-suite/src/whitelist_merkletree.rs +++ b/test-suite/src/whitelist_merkletree.rs @@ -1 +1 @@ -mod tests; \ No newline at end of file +mod tests; diff --git a/test-suite/src/whitelist_merkletree/tests.rs b/test-suite/src/whitelist_merkletree/tests.rs index 6b4013a43..07214813c 100644 --- a/test-suite/src/whitelist_merkletree/tests.rs +++ b/test-suite/src/whitelist_merkletree/tests.rs @@ -1 +1 @@ -mod integration_tests; \ No newline at end of file +mod integration_tests; diff --git a/test-suite/src/whitelist_merkletree/tests/integration_tests.rs b/test-suite/src/whitelist_merkletree/tests/integration_tests.rs index 2302694e2..6f846f256 100644 --- a/test-suite/src/whitelist_merkletree/tests/integration_tests.rs +++ b/test-suite/src/whitelist_merkletree/tests/integration_tests.rs @@ -1,24 +1,23 @@ #[cfg(test)] mod tests { - use cosmwasm_std::{Addr, Timestamp, coin}; + use cosmwasm_std::{coin, Addr, Timestamp}; use cw_multi_test::Executor; use rs_merkle::MerkleTree; use sg_multi_test::StargazeApp; use sg_std::{GENESIS_MINT_START_TIME, NATIVE_DENOM}; - + use whitelist_mtree::{ + msg::*, tests::{hasher::SortingSha256Hasher, test_helpers::hash_and_build_tree}, - msg::* }; use crate::common_setup::contract_boxes::{contract_whitelist_merkletree, custom_mock_app}; - type Tree = MerkleTree::; + type Tree = MerkleTree; const CREATOR: &str = "creator"; const START_TIME: Timestamp = Timestamp::from_nanos(GENESIS_MINT_START_TIME); const END_TIME: Timestamp = Timestamp::from_nanos(GENESIS_MINT_START_TIME + 1000); - fn get_init_address_list_1() -> Vec { vec![ @@ -47,7 +46,7 @@ mod tests { pub fn instantiate_with_root( app: &mut StargazeApp, per_address_limit: u32, - merkle_root: String + merkle_root: String, ) -> Addr { let msg = InstantiateMsg { admins: vec![], @@ -57,7 +56,7 @@ mod tests { mint_price: coin(1000000u128, NATIVE_DENOM), per_address_limit, merkle_root, - merkle_tree_uri: None + merkle_tree_uri: None, }; let wl_id = app.store_code(contract_whitelist_merkletree()); app.instantiate_contract( @@ -71,31 +70,29 @@ mod tests { .unwrap() } - - pub fn query_admin_list(app: &mut StargazeApp, wl_addr: Addr) { let res: AdminListResponse = app .wrap() - .query_wasm_smart(wl_addr, &QueryMsg::AdminList { }) + .query_wasm_smart(wl_addr, &QueryMsg::AdminList {}) .unwrap(); assert_eq!(res.admins.len(), 0); - assert_eq!(res.mutable, false) + assert!(!res.mutable) } pub fn query_includes_address( - app: &mut StargazeApp, - wl_addr: Addr, + app: &mut StargazeApp, + wl_addr: Addr, addr_to_check: String, - proof_hashes: Vec + proof_hashes: Vec, ) { let res: HasMemberResponse = app .wrap() .query_wasm_smart( wl_addr, - &QueryMsg::HasMember { - member: addr_to_check.to_string(), - proof_hashes - } + &QueryMsg::HasMember { + member: addr_to_check.to_string(), + proof_hashes, + }, ) .unwrap(); assert!(res.has_member); @@ -116,9 +113,9 @@ mod tests { let per_address_limit = 1; let tree: Tree = hash_and_build_tree(&addrs); let wl_addr = instantiate_with_root(&mut app, per_address_limit, tree.root_hex().unwrap()); - + let addr_to_check = addrs[0].clone(); - let proof = tree.proof(&vec![0]); + let proof = tree.proof(&[0]); let proof_hashes = proof.proof_hashes_hex(); query_includes_address(&mut app, wl_addr.clone(), addr_to_check, proof_hashes); @@ -131,12 +128,12 @@ mod tests { let mut app = custom_mock_app(); let addrs = get_init_address_list_2(); let per_address_limit = 99; - + let tree: Tree = hash_and_build_tree(&addrs); let wl_addr = instantiate_with_root(&mut app, per_address_limit, tree.root_hex().unwrap()); let addr_to_check = addrs[1].clone(); - let proof = tree.proof(&vec![1]); + let proof = tree.proof(&[1]); let proof_hashes = proof.proof_hashes_hex(); query_admin_list(&mut app, wl_addr.clone()); @@ -152,16 +149,14 @@ mod tests { let tree: Tree = hash_and_build_tree(&addrs); let wl_addr = instantiate_with_root(&mut app, per_address_limit, tree.root_hex().unwrap()); - + let addr_to_check = addrs[0].clone(); query_admin_list(&mut app, wl_addr.clone()); - let proof = tree.proof(&vec![0]); + let proof = tree.proof(&[0]); let proof_hashes = proof.proof_hashes_hex(); query_includes_address(&mut app, wl_addr.clone(), addr_to_check, proof_hashes); query_per_address_limit(&mut app, wl_addr, per_address_limit) } - - }