mirror of
https://github.com/alexgo-io/stacks-subnets.git
synced 2026-04-30 20:52:16 +08:00
Renamed hyperchains to subnets.
This commit is contained in:
@@ -25,15 +25,15 @@ depends_on = ["trait-standards"]
|
||||
path = "contracts/helper/simple-ft.clar"
|
||||
depends_on = ["trait-standards"]
|
||||
|
||||
[contracts.hyperchains]
|
||||
path = "contracts/hyperchains.clar"
|
||||
[contracts.subnet]
|
||||
path = "contracts/subnet.clar"
|
||||
depends_on = ["trait-standards"]
|
||||
clarity_version = 2
|
||||
epoch = 2.1
|
||||
|
||||
[contracts.multi-miner]
|
||||
path = "contracts/multi-miner.clar"
|
||||
depends_on = ["hyperchains"]
|
||||
depends_on = ["subnet"]
|
||||
clarity_version = 2
|
||||
epoch = 2.1
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
(define-trait mint-from-hyperchain-trait
|
||||
(
|
||||
;; Transfer from the sender to a new principal
|
||||
(mint-from-hyperchain (uint principal principal) (response bool uint))
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
(define-trait mint-from-subnet-trait
|
||||
(
|
||||
;; Transfer from the sender to a new principal
|
||||
(mint-from-subnet (uint principal principal) (response bool uint))
|
||||
)
|
||||
)
|
||||
@@ -1,7 +1,7 @@
|
||||
(define-constant ERR_NOT_AUTHORIZED (err u1001))
|
||||
|
||||
(impl-trait .trait-standards.ft-trait)
|
||||
(impl-trait .trait-standards.mint-from-hyperchain-trait)
|
||||
(impl-trait .trait-standards.mint-from-subnet-trait)
|
||||
|
||||
(define-fungible-token ft-token)
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
(define-read-only (get-decimals)
|
||||
(ok u0))
|
||||
|
||||
;; Implement mint-from-hyperchain trait
|
||||
(define-public (mint-from-hyperchain (amount uint) (sender principal) (recipient principal))
|
||||
;; Implement mint-from-subnet trait
|
||||
(define-public (mint-from-subnet (amount uint) (sender principal) (recipient principal))
|
||||
(begin
|
||||
;; Check that the tx-sender is the provided sender
|
||||
(asserts! (is-eq tx-sender sender) ERR_NOT_AUTHORIZED)
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
)
|
||||
|
||||
;; deposit function
|
||||
(define-public (hyperchain-deposit-nft-token (id uint) (recipient principal))
|
||||
(define-public (subnet-deposit-nft-token (id uint) (recipient principal))
|
||||
(begin
|
||||
(nft-mint? nft-token id recipient)
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
;; This is like `simple-nft.clar`, but does not support minting from hyperchain.
|
||||
;; This is like `simple-nft.clar`, but does not support minting from a subnet.
|
||||
|
||||
(define-constant CONTRACT_OWNER tx-sender)
|
||||
(define-constant CONTRACT_ADDRESS (as-contract tx-sender))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
(define-constant ERR_NOT_AUTHORIZED (err u1001))
|
||||
|
||||
(impl-trait .trait-standards.nft-trait)
|
||||
(impl-trait .trait-standards.mint-from-hyperchain-trait)
|
||||
(impl-trait .trait-standards.mint-from-subnet-trait)
|
||||
|
||||
(define-data-var lastId uint u0)
|
||||
(define-map CFG_BASE_URI bool (string-ascii 256))
|
||||
@@ -39,7 +39,7 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-public (mint-from-hyperchain (id uint) (sender principal) (recipient principal))
|
||||
(define-public (mint-from-subnet (id uint) (sender principal) (recipient principal))
|
||||
(begin
|
||||
;; Check that the tx-sender is the provided sender
|
||||
(asserts! (is-eq tx-sender sender) ERR_NOT_AUTHORIZED)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
;; Contains functions used in testing the hyperchains contract.
|
||||
;; Contains functions used in testing the subnet contract.
|
||||
|
||||
;; Returns the `id-header-hash` of the chain tip. This is used for `clarinet` tests
|
||||
;; where we do not yet have access to this value through the API.
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-trait mint-from-hyperchain-trait
|
||||
(define-trait mint-from-subnet-trait
|
||||
(
|
||||
;; Transfer from the sender to a new principal
|
||||
(mint-from-hyperchain (uint principal principal) (response bool uint))
|
||||
(mint-from-subnet (uint principal principal) (response bool uint))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
;; SIP-018 Constants
|
||||
(define-constant sip18-prefix 0x534950303138)
|
||||
;; (define-constant (sha256 (unwrap-panic (to-consensus-buff { name: "hyperchain-multi-miner", version: "1.0.0", chain-id: u1 }))))
|
||||
;; (define-constant (sha256 (unwrap-panic (to-consensus-buff { name: "subnet-multi-miner", version: "1.0.0", chain-id: u1 }))))
|
||||
(define-constant sip18-domain-hash 0x81c24181e24119f609a28023c4943d3a41592656eb90560c15ee02b8e1ce19b8)
|
||||
(define-constant sip18-data-prefix (concat sip18-prefix sip18-domain-hash))
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
(define-private (get-miners)
|
||||
(unwrap-panic (var-get miners)))
|
||||
|
||||
;; Set the hc miners for this contract. Can be called by *anyone*
|
||||
;; Set the subnet miners for this contract. Can be called by *anyone*
|
||||
;; before the miner is set. This is an unsafe way to initialize the
|
||||
;; contract, because a re-org could allow someone to reinitialize
|
||||
;; this field. Instead, authors should initialize the variable
|
||||
@@ -81,4 +81,4 @@
|
||||
;; check that we have enough signatures
|
||||
(try! (check-miners (append (get signers signer-principals) tx-sender)))
|
||||
;; execute the block commit
|
||||
(as-contract (contract-call? .hyperchains commit-block (get block block-data) (get target-tip block-data) (get withdrawal-root block-data)))))
|
||||
(as-contract (contract-call? .subnet commit-block (get block block-data) (get target-tip block-data) (get withdrawal-root block-data)))))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
;; The .hyperchains contract
|
||||
;; The .subnet contract
|
||||
|
||||
(define-constant CONTRACT_ADDRESS (as-contract tx-sender))
|
||||
|
||||
@@ -45,15 +45,15 @@
|
||||
;; Use trait declarations
|
||||
(use-trait nft-trait .trait-standards.nft-trait)
|
||||
(use-trait ft-trait .trait-standards.ft-trait)
|
||||
(use-trait mint-from-hyperchain-trait .trait-standards.mint-from-hyperchain-trait)
|
||||
(use-trait mint-from-subnet-trait .trait-standards.mint-from-subnet-trait)
|
||||
|
||||
;; Set the hc miner for this contract. Can be called by *anyone*
|
||||
;; Set the subnet miner for this contract. Can be called by *anyone*
|
||||
;; before the miner is set. This is an unsafe way to initialize the
|
||||
;; contract, because a re-org could allow someone to reinitialize
|
||||
;; this field. Instead, authors should initialize the variable
|
||||
;; directly at the data-var instantiation. This is used for testing
|
||||
;; purposes only.
|
||||
(define-public (set-hc-miner (miner-to-set principal))
|
||||
(define-public (set-subnet-miner (miner-to-set principal))
|
||||
(match (var-get miner) existing-miner (err ERR_MINER_ALREADY_SET)
|
||||
(begin
|
||||
(var-set miner (some miner-to-set))
|
||||
@@ -70,9 +70,9 @@
|
||||
(err ERR_INVALID_MINER))
|
||||
|
||||
;; Set up the assets that the contract is allowed to transfer
|
||||
(asserts! (map-insert allowed-contracts .simple-ft "hyperchain-deposit-ft-token") (err ERR_ASSET_ALREADY_ALLOWED))
|
||||
(asserts! (map-insert allowed-contracts .simple-nft "hyperchain-deposit-nft-token") (err ERR_ASSET_ALREADY_ALLOWED))
|
||||
(asserts! (map-insert allowed-contracts .simple-nft-no-mint "hyperchain-deposit-nft-token-no-mint") (err ERR_ASSET_ALREADY_ALLOWED))
|
||||
(asserts! (map-insert allowed-contracts .simple-ft "subnet-deposit-ft-token") (err ERR_ASSET_ALREADY_ALLOWED))
|
||||
(asserts! (map-insert allowed-contracts .simple-nft "subnet-deposit-nft-token") (err ERR_ASSET_ALREADY_ALLOWED))
|
||||
(asserts! (map-insert allowed-contracts .simple-nft-no-mint "subnet-deposit-nft-token-no-mint") (err ERR_ASSET_ALREADY_ALLOWED))
|
||||
|
||||
(ok true)
|
||||
)
|
||||
@@ -184,9 +184,9 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-private (inner-mint-nft-asset (id uint) (sender principal) (recipient principal) (nft-mint-contract <mint-from-hyperchain-trait>))
|
||||
(define-private (inner-mint-nft-asset (id uint) (sender principal) (recipient principal) (nft-mint-contract <mint-from-subnet-trait>))
|
||||
(let (
|
||||
(call-result (as-contract (contract-call? nft-mint-contract mint-from-hyperchain id sender recipient)))
|
||||
(call-result (as-contract (contract-call? nft-mint-contract mint-from-subnet id sender recipient)))
|
||||
(mint-result (unwrap! call-result (err ERR_CONTRACT_CALL_FAILED)))
|
||||
)
|
||||
;; Check that the transfer succeeded
|
||||
@@ -196,7 +196,7 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-private (inner-transfer-or-mint-nft-asset (id uint) (recipient principal) (nft-contract <nft-trait>) (nft-mint-contract <mint-from-hyperchain-trait>))
|
||||
(define-private (inner-transfer-or-mint-nft-asset (id uint) (recipient principal) (nft-contract <nft-trait>) (nft-mint-contract <mint-from-subnet-trait>))
|
||||
(let (
|
||||
(call-result (contract-call? nft-contract get-owner id))
|
||||
(nft-owner (unwrap! call-result (err ERR_CONTRACT_CALL_FAILED)))
|
||||
@@ -219,18 +219,18 @@
|
||||
;; A user calls this function to deposit an NFT into the contract.
|
||||
;; The function emits a print with details of this event.
|
||||
;; Returns response<bool, int>
|
||||
(define-public (deposit-nft-asset (id uint) (sender principal) (nft-contract <nft-trait>) (hc-contract-id principal))
|
||||
(define-public (deposit-nft-asset (id uint) (sender principal) (nft-contract <nft-trait>) (subnet-contract-id principal))
|
||||
(let (
|
||||
;; Check that the asset belongs to the allowed-contracts map
|
||||
(hc-function-name (unwrap! (map-get? allowed-contracts (contract-of nft-contract)) (err ERR_DISALLOWED_ASSET)))
|
||||
(subnet-function-name (unwrap! (map-get? allowed-contracts (contract-of nft-contract)) (err ERR_DISALLOWED_ASSET)))
|
||||
)
|
||||
|
||||
;; Try to transfer the NFT to this contract
|
||||
(asserts! (try! (inner-transfer-nft-asset id sender CONTRACT_ADDRESS nft-contract)) (err ERR_TRANSFER_FAILED))
|
||||
|
||||
;; Emit a print event - the node consumes this
|
||||
(print { event: "deposit-nft", nft-id: id, l1-contract-id: nft-contract, hc-contract-id: hc-contract-id,
|
||||
sender: sender, hc-function-name: hc-function-name })
|
||||
(print { event: "deposit-nft", nft-id: id, l1-contract-id: nft-contract, subnet-contract-id: subnet-contract-id,
|
||||
sender: sender, subnet-function-name: subnet-function-name })
|
||||
|
||||
(ok true)
|
||||
)
|
||||
@@ -239,7 +239,7 @@
|
||||
|
||||
;; Helper function for `withdraw-nft-asset`
|
||||
;; Returns response<bool, int>
|
||||
(define-public (inner-withdraw-nft-asset (id uint) (recipient principal) (withdrawal-id uint) (height uint) (nft-contract <nft-trait>) (nft-mint-contract (optional <mint-from-hyperchain-trait>)) (withdrawal-root (buff 32)) (withdrawal-leaf-hash (buff 32)) (sibling-hashes (list 50 (tuple (hash (buff 32)) (is-left-side bool) ) )))
|
||||
(define-public (inner-withdraw-nft-asset (id uint) (recipient principal) (withdrawal-id uint) (height uint) (nft-contract <nft-trait>) (nft-mint-contract (optional <mint-from-subnet-trait>)) (withdrawal-root (buff 32)) (withdrawal-leaf-hash (buff 32)) (sibling-hashes (list 50 (tuple (hash (buff 32)) (is-left-side bool) ) )))
|
||||
(let ((hashes-are-valid (check-withdrawal-hashes withdrawal-root withdrawal-leaf-hash sibling-hashes)))
|
||||
|
||||
(asserts! (try! hashes-are-valid) (err ERR_VALIDATION_FAILED))
|
||||
@@ -267,13 +267,13 @@
|
||||
|
||||
;; A user calls this function to withdraw the specified NFT from this contract.
|
||||
;; In order for this withdrawal to go through, the given withdrawal must have been included
|
||||
;; in a withdrawal Merkle tree a hyperchain miner submitted. The user must provide the leaf
|
||||
;; in a withdrawal Merkle tree a subnet miner submitted. The user must provide the leaf
|
||||
;; hash of their withdrawal and the root hash of the specific Merkle tree their withdrawal
|
||||
;; is included in. They must also provide a list of sibling hashes. The withdraw function
|
||||
;; uses the provided hashes to ensure the requested withdrawal is valid.
|
||||
;; The function emits a print with details of this event.
|
||||
;; Returns response<bool, int>
|
||||
(define-public (withdraw-nft-asset (id uint) (recipient principal) (withdrawal-id uint) (height uint) (nft-contract <nft-trait>) (nft-mint-contract (optional <mint-from-hyperchain-trait>)) (withdrawal-root (buff 32)) (withdrawal-leaf-hash (buff 32)) (sibling-hashes (list 50 (tuple (hash (buff 32)) (is-left-side bool) ) )))
|
||||
(define-public (withdraw-nft-asset (id uint) (recipient principal) (withdrawal-id uint) (height uint) (nft-contract <nft-trait>) (nft-mint-contract (optional <mint-from-subnet-trait>)) (withdrawal-root (buff 32)) (withdrawal-leaf-hash (buff 32)) (sibling-hashes (list 50 (tuple (hash (buff 32)) (is-left-side bool) ) )))
|
||||
(begin
|
||||
;; Check that the asset belongs to the allowed-contracts map
|
||||
(unwrap! (map-get? allowed-contracts (contract-of nft-contract)) (err ERR_DISALLOWED_ASSET))
|
||||
@@ -319,9 +319,9 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-private (inner-mint-ft-asset (amount uint) (sender principal) (recipient principal) (ft-mint-contract <mint-from-hyperchain-trait>))
|
||||
(define-private (inner-mint-ft-asset (amount uint) (sender principal) (recipient principal) (ft-mint-contract <mint-from-subnet-trait>))
|
||||
(let (
|
||||
(call-result (as-contract (contract-call? ft-mint-contract mint-from-hyperchain amount sender recipient)))
|
||||
(call-result (as-contract (contract-call? ft-mint-contract mint-from-subnet amount sender recipient)))
|
||||
(mint-result (unwrap! call-result (err ERR_CONTRACT_CALL_FAILED)))
|
||||
)
|
||||
;; Check that the transfer succeeded
|
||||
@@ -331,7 +331,7 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define-private (inner-transfer-or-mint-ft-asset (amount uint) (recipient principal) (memo (optional (buff 34))) (ft-contract <ft-trait>) (ft-mint-contract <mint-from-hyperchain-trait>))
|
||||
(define-private (inner-transfer-or-mint-ft-asset (amount uint) (recipient principal) (memo (optional (buff 34))) (ft-contract <ft-trait>) (ft-mint-contract <mint-from-subnet-trait>))
|
||||
(let (
|
||||
(call-result (contract-call? ft-contract get-balance CONTRACT_ADDRESS))
|
||||
(contract-ft-balance (unwrap! call-result (err ERR_CONTRACT_CALL_FAILED)))
|
||||
@@ -362,10 +362,10 @@
|
||||
;; A user calls this function to deposit a fungible token into the contract.
|
||||
;; The function emits a print with details of this event.
|
||||
;; Returns response<bool, int>
|
||||
(define-public (deposit-ft-asset (amount uint) (sender principal) (memo (optional (buff 34))) (ft-contract <ft-trait>) (hc-contract-id principal))
|
||||
(define-public (deposit-ft-asset (amount uint) (sender principal) (memo (optional (buff 34))) (ft-contract <ft-trait>) (subnet-contract-id principal))
|
||||
(let (
|
||||
;; Check that the asset belongs to the allowed-contracts map
|
||||
(hc-function-name (unwrap! (map-get? allowed-contracts (contract-of ft-contract)) (err ERR_DISALLOWED_ASSET)))
|
||||
(subnet-function-name (unwrap! (map-get? allowed-contracts (contract-of ft-contract)) (err ERR_DISALLOWED_ASSET)))
|
||||
)
|
||||
;; Try to transfer the FT to this contract
|
||||
(asserts! (try! (inner-transfer-ft-asset amount sender CONTRACT_ADDRESS memo ft-contract)) (err ERR_TRANSFER_FAILED))
|
||||
@@ -375,7 +375,7 @@
|
||||
)
|
||||
;; Emit a print event - the node consumes this
|
||||
(print { event: "deposit-ft", ft-amount: amount, l1-contract-id: ft-contract,
|
||||
ft-name: ft-name, hc-contract-id: hc-contract-id, sender: sender, hc-function-name: hc-function-name })
|
||||
ft-name: ft-name, subnet-contract-id: subnet-contract-id, sender: sender, subnet-function-name: subnet-function-name })
|
||||
)
|
||||
|
||||
(ok true)
|
||||
@@ -384,7 +384,7 @@
|
||||
|
||||
;; This function performs validity checks related to the withdrawal and performs the withdrawal as well.
|
||||
;; Returns response<bool, int>
|
||||
(define-private (inner-withdraw-ft-asset (amount uint) (recipient principal) (withdrawal-id uint) (height uint) (memo (optional (buff 34))) (ft-contract <ft-trait>) (ft-mint-contract <mint-from-hyperchain-trait>) (withdrawal-root (buff 32)) (withdrawal-leaf-hash (buff 32)) (sibling-hashes (list 50 (tuple (hash (buff 32)) (is-left-side bool) ) )))
|
||||
(define-private (inner-withdraw-ft-asset (amount uint) (recipient principal) (withdrawal-id uint) (height uint) (memo (optional (buff 34))) (ft-contract <ft-trait>) (ft-mint-contract <mint-from-subnet-trait>) (withdrawal-root (buff 32)) (withdrawal-leaf-hash (buff 32)) (sibling-hashes (list 50 (tuple (hash (buff 32)) (is-left-side bool) ) )))
|
||||
(let ((hashes-are-valid (check-withdrawal-hashes withdrawal-root withdrawal-leaf-hash sibling-hashes)))
|
||||
(asserts! (try! hashes-are-valid) (err ERR_VALIDATION_FAILED))
|
||||
|
||||
@@ -404,13 +404,13 @@
|
||||
;; A user can call this function to withdraw some amount of a fungible token asset from the
|
||||
;; contract and send it to a recipient.
|
||||
;; In order for this withdrawal to go through, the given withdrawal must have been included
|
||||
;; in a withdrawal Merkle tree a hyperchain miner submitted. The user must provide the leaf
|
||||
;; in a withdrawal Merkle tree a subnet miner submitted. The user must provide the leaf
|
||||
;; hash of their withdrawal and the root hash of the specific Merkle tree their withdrawal
|
||||
;; is included in. They must also provide a list of sibling hashes. The withdraw function
|
||||
;; uses the provided hashes to ensure the requested withdrawal is valid.
|
||||
;; The function emits a print with details of this event.
|
||||
;; Returns response<bool, int>
|
||||
(define-public (withdraw-ft-asset (amount uint) (recipient principal) (withdrawal-id uint) (height uint) (memo (optional (buff 34))) (ft-contract <ft-trait>) (ft-mint-contract <mint-from-hyperchain-trait>) (withdrawal-root (buff 32)) (withdrawal-leaf-hash (buff 32)) (sibling-hashes (list 50 (tuple (hash (buff 32)) (is-left-side bool) ) )))
|
||||
(define-public (withdraw-ft-asset (amount uint) (recipient principal) (withdrawal-id uint) (height uint) (memo (optional (buff 34))) (ft-contract <ft-trait>) (ft-mint-contract <mint-from-subnet-trait>) (withdrawal-root (buff 32)) (withdrawal-leaf-hash (buff 32)) (sibling-hashes (list 50 (tuple (hash (buff 32)) (is-left-side bool) ) )))
|
||||
(begin
|
||||
;; Check that the withdraw amount is positive
|
||||
(asserts! (> amount u0) (err ERR_ATTEMPT_TO_TRANSFER_ZERO_AMOUNT))
|
||||
@@ -502,7 +502,7 @@
|
||||
|
||||
;; A user calls this function to withdraw STX from this contract.
|
||||
;; In order for this withdrawal to go through, the given withdrawal must have been included
|
||||
;; in a withdrawal Merkle tree a hyperchain miner submitted. The user must provide the leaf
|
||||
;; in a withdrawal Merkle tree a subnet miner submitted. The user must provide the leaf
|
||||
;; hash of their withdrawal and the root hash of the specific Merkle tree their withdrawal
|
||||
;; is included in. They must also provide a list of sibling hashes. The withdraw function
|
||||
;; uses the provided hashes to ensure the requested withdrawal is valid.
|
||||
@@ -54,10 +54,10 @@ Clarinet.test({
|
||||
address: "STECHMJGSBWNGW3MS334R3PHQD4F59EFMAXY7Y7F"
|
||||
};
|
||||
|
||||
// set the multi_miner_contract as the miner of the hyperchains contract
|
||||
// set the multi_miner_contract as the miner of the subnet contract
|
||||
// and set alice and signatory as miners in the multi-miner contract
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(multi_miner_contract),
|
||||
],
|
||||
@@ -179,10 +179,10 @@ Clarinet.test({
|
||||
address: "STECHMJGSBWNGW3MS334R3PHQD4F59EFMAXY7Y7F"
|
||||
};
|
||||
|
||||
// set the multi_miner_contract as the miner of the hyperchains contract
|
||||
// set the multi_miner_contract as the miner of the subnet contract
|
||||
// and set signatory1 and signatory2 as miners in the multi-miner contract
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(multi_miner_contract),
|
||||
],
|
||||
@@ -15,7 +15,7 @@ Clarinet.test({
|
||||
// Test data comes from clarity_vm::withdrawal tests
|
||||
const block_height = 0;
|
||||
const recipient = "ST18F1AHKW194BWQ3CEFDPWVRARA79RBGFEWSDQR8";
|
||||
const leaf_hash_1 = chain.callReadOnlyFn('hyperchains', 'leaf-hash-withdraw-stx', [
|
||||
const leaf_hash_1 = chain.callReadOnlyFn('subnet', 'leaf-hash-withdraw-stx', [
|
||||
types.uint(1),
|
||||
types.principal(recipient),
|
||||
types.uint(0),
|
||||
@@ -26,7 +26,7 @@ Clarinet.test({
|
||||
const ft_contract = "ST18F1AHKW194BWQ3CEFDPWVRARA79RBGFEWSDQR8.simple-ft";
|
||||
const nft_contract = "ST18F1AHKW194BWQ3CEFDPWVRARA79RBGFEWSDQR8.simple-nft";
|
||||
|
||||
const leaf_hash_2 = chain.callReadOnlyFn('hyperchains', 'leaf-hash-withdraw-ft', [
|
||||
const leaf_hash_2 = chain.callReadOnlyFn('subnet', 'leaf-hash-withdraw-ft', [
|
||||
types.principal(ft_contract),
|
||||
types.uint(1),
|
||||
types.principal(recipient),
|
||||
@@ -35,7 +35,7 @@ Clarinet.test({
|
||||
], alice).result.toString();
|
||||
assertEquals(leaf_hash_2, "0x33dcd4279c21663c457927c300fe58e415e518b34e6ae90018d536cc69cda811");
|
||||
|
||||
const leaf_hash_3 = chain.callReadOnlyFn('hyperchains', 'leaf-hash-withdraw-nft', [
|
||||
const leaf_hash_3 = chain.callReadOnlyFn('subnet', 'leaf-hash-withdraw-nft', [
|
||||
types.principal(nft_contract),
|
||||
types.uint(1),
|
||||
types.principal(recipient),
|
||||
@@ -58,7 +58,7 @@ Clarinet.test({
|
||||
|
||||
// set alice as a miner
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(alice.address),
|
||||
],
|
||||
@@ -69,7 +69,7 @@ Clarinet.test({
|
||||
|
||||
let block = chain.mineBlock([
|
||||
// Successfully commit block at height 0 with alice.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash1,
|
||||
@@ -77,7 +77,7 @@ Clarinet.test({
|
||||
],
|
||||
alice.address),
|
||||
// Try and fail to commit a different block, but again at height 0.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 2, 2, 2, 2])),
|
||||
id_header_hash1,
|
||||
@@ -97,7 +97,7 @@ Clarinet.test({
|
||||
// Try and fail to commit a block at height 1 with an invalid miner.
|
||||
const id_header_hash2 = chain.callReadOnlyFn('test-helpers', 'get-id-header-hash', [], alice.address).result.expectOk().toString();
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 2, 2, 2, 2])),
|
||||
id_header_hash2,
|
||||
@@ -113,7 +113,7 @@ Clarinet.test({
|
||||
// Successfully commit block at height 1 with valid miner.
|
||||
const id_header_hash3 = chain.callReadOnlyFn('test-helpers', 'get-id-header-hash', [], alice.address).result.expectOk().toString();
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 2, 2, 2, 2])),
|
||||
id_header_hash3,
|
||||
@@ -143,7 +143,7 @@ Clarinet.test({
|
||||
|
||||
// set alice as a miner
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(alice.address),
|
||||
],
|
||||
@@ -152,7 +152,7 @@ Clarinet.test({
|
||||
|
||||
// Invalid miner can't setup allowed assets
|
||||
let block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
bob.address),
|
||||
]);
|
||||
@@ -163,7 +163,7 @@ Clarinet.test({
|
||||
|
||||
// Miner can set up allowed assets
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -173,7 +173,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should not be able to set up allowed assets a second time
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -184,10 +184,10 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to register a new allowed NFT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "register-new-nft-contract",
|
||||
Tx.contractCall("subnet", "register-new-nft-contract",
|
||||
[
|
||||
types.principal(second_nft_contract.contract_id),
|
||||
types.ascii("deposit-on-hc"),
|
||||
types.ascii("deposit-on-subnet"),
|
||||
],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -197,10 +197,10 @@ Clarinet.test({
|
||||
|
||||
// Miner should be not able to register a previously allowed NFT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "register-new-nft-contract",
|
||||
Tx.contractCall("subnet", "register-new-nft-contract",
|
||||
[
|
||||
types.principal(second_nft_contract.contract_id),
|
||||
types.ascii("deposit-on-hc"),
|
||||
types.ascii("deposit-on-subnet"),
|
||||
],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -211,10 +211,10 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to register a new allowed FT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "register-new-ft-contract",
|
||||
Tx.contractCall("subnet", "register-new-ft-contract",
|
||||
[
|
||||
types.principal(second_ft_contract.contract_id),
|
||||
types.ascii("deposit-on-hc"),
|
||||
types.ascii("deposit-on-subnet"),
|
||||
],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -224,10 +224,10 @@ Clarinet.test({
|
||||
|
||||
// Miner should be not able to register a previously allowed FT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "register-new-ft-contract",
|
||||
Tx.contractCall("subnet", "register-new-ft-contract",
|
||||
[
|
||||
types.principal(second_ft_contract.contract_id),
|
||||
types.ascii("deposit-on-hc"),
|
||||
types.ascii("deposit-on-subnet"),
|
||||
],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -253,7 +253,7 @@ Clarinet.test({
|
||||
|
||||
// set alice as a miner
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(alice.address),
|
||||
],
|
||||
@@ -262,7 +262,7 @@ Clarinet.test({
|
||||
|
||||
// nft contract id
|
||||
const nft_contract = contracts.get("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.simple-nft")!;
|
||||
const hyperchain_contract = contracts.get("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.hyperchains")!;
|
||||
const subnet_contract = contracts.get("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.subnet")!;
|
||||
|
||||
// User should be able to mint an NFT
|
||||
let block = chain.mineBlock([
|
||||
@@ -276,7 +276,7 @@ Clarinet.test({
|
||||
|
||||
// User should not be able to deposit NFT asset before miner allows the asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-nft-asset",
|
||||
Tx.contractCall("subnet", "deposit-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -292,7 +292,7 @@ Clarinet.test({
|
||||
|
||||
// Invalid miner can't setup allowed assets
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
bob.address),
|
||||
]);
|
||||
@@ -303,7 +303,7 @@ Clarinet.test({
|
||||
|
||||
// Miner sets up allowed assets
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -313,7 +313,7 @@ Clarinet.test({
|
||||
|
||||
// User should be able to deposit NFT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-nft-asset",
|
||||
Tx.contractCall("subnet", "deposit-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -329,12 +329,12 @@ Clarinet.test({
|
||||
assets = chain.getAssetsMaps().assets[".simple-nft.nft-token"];
|
||||
nft_amount = assets[charlie.address];
|
||||
assertEquals(nft_amount, 0);
|
||||
nft_amount = assets[hyperchain_contract.contract_id];
|
||||
nft_amount = assets[subnet_contract.contract_id];
|
||||
assertEquals(nft_amount, 1);
|
||||
|
||||
// User should not be able to deposit an NFT asset they don't own
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-nft-asset",
|
||||
Tx.contractCall("subnet", "deposit-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -357,7 +357,7 @@ Clarinet.test({
|
||||
|
||||
block = chain.mineBlock([
|
||||
// Successfully commit block at height 0 with alice.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash,
|
||||
@@ -371,7 +371,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to withdraw NFT asset for user
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -401,7 +401,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should not be able to withdraw NFT asset a second time
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -444,7 +444,7 @@ Clarinet.test({
|
||||
|
||||
// set alice as a miner
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(alice.address),
|
||||
],
|
||||
@@ -464,7 +464,7 @@ Clarinet.test({
|
||||
|
||||
// User should not be able to deposit FT assets if they are not allowed
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-ft-asset",
|
||||
Tx.contractCall("subnet", "deposit-ft-asset",
|
||||
[
|
||||
types.uint(2),
|
||||
types.principal(charlie.address),
|
||||
@@ -481,7 +481,7 @@ Clarinet.test({
|
||||
|
||||
// Invalid miner can't setup allowed assets
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
bob.address),
|
||||
]);
|
||||
@@ -492,7 +492,7 @@ Clarinet.test({
|
||||
|
||||
// Miner sets up allowed assets
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -502,7 +502,7 @@ Clarinet.test({
|
||||
|
||||
// User should not be able to deposit a larger quantity than they own
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-ft-asset",
|
||||
Tx.contractCall("subnet", "deposit-ft-asset",
|
||||
[
|
||||
types.uint(3),
|
||||
types.principal(charlie.address),
|
||||
@@ -519,7 +519,7 @@ Clarinet.test({
|
||||
|
||||
// User should be able to deposit FT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-ft-asset",
|
||||
Tx.contractCall("subnet", "deposit-ft-asset",
|
||||
[
|
||||
types.uint(2),
|
||||
types.principal(charlie.address),
|
||||
@@ -535,7 +535,7 @@ Clarinet.test({
|
||||
|
||||
// User should not be able to deposit an FT asset they don't own
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-ft-asset",
|
||||
Tx.contractCall("subnet", "deposit-ft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -558,7 +558,7 @@ Clarinet.test({
|
||||
const id_header_hash = chain.callReadOnlyFn('test-helpers', 'get-id-header-hash', [], alice.address).result.expectOk().toString();
|
||||
block = chain.mineBlock([
|
||||
// Successfully commit block at height 0 with alice.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash,
|
||||
@@ -572,7 +572,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to withdraw FT asset for user
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-ft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-ft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -602,7 +602,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should not be able to withdraw FT asset a second time
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-ft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-ft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -629,7 +629,7 @@ Clarinet.test({
|
||||
});
|
||||
|
||||
Clarinet.test({
|
||||
name: "Ensure that user can withdraw FT minted on hyperchain & L1 miner can mint it",
|
||||
name: "Ensure that user can withdraw FT minted on subnet & L1 miner can mint it",
|
||||
async fn(chain: Chain, accounts: Map<string, Account>, contracts: Map<string, Contract>) {
|
||||
|
||||
// miner
|
||||
@@ -642,7 +642,7 @@ Clarinet.test({
|
||||
|
||||
// set alice as a miner
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(alice.address),
|
||||
],
|
||||
@@ -662,7 +662,7 @@ Clarinet.test({
|
||||
|
||||
// Miner sets up allowed assets
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -672,7 +672,7 @@ Clarinet.test({
|
||||
|
||||
// User should be able to deposit FT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-ft-asset",
|
||||
Tx.contractCall("subnet", "deposit-ft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -700,7 +700,7 @@ Clarinet.test({
|
||||
const id_header_hash = chain.callReadOnlyFn('test-helpers', 'get-id-header-hash', [], alice.address).result.expectOk().toString();
|
||||
block = chain.mineBlock([
|
||||
// Successfully commit block at height 0 with alice.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash,
|
||||
@@ -714,7 +714,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to withdraw FT asset for user
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-ft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-ft-asset",
|
||||
[
|
||||
types.uint(3),
|
||||
types.principal(charlie.address),
|
||||
@@ -744,7 +744,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be not be able to withdraw FT asset with same hash
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-ft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-ft-asset",
|
||||
[
|
||||
types.uint(3),
|
||||
types.principal(charlie.address),
|
||||
@@ -771,7 +771,7 @@ Clarinet.test({
|
||||
// User should be not be able to withdraw 0 amount of FT asset
|
||||
// This test works since the amount is checked before the leaf hash is checked
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-ft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-ft-asset",
|
||||
[
|
||||
types.uint(0),
|
||||
types.principal(charlie.address),
|
||||
@@ -817,7 +817,7 @@ Clarinet.test({
|
||||
|
||||
// set alice as a miner
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(alice.address),
|
||||
],
|
||||
@@ -842,7 +842,7 @@ Clarinet.test({
|
||||
|
||||
// Miner sets up allowed assets
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -862,7 +862,7 @@ Clarinet.test({
|
||||
|
||||
// User should be able to deposit FT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-ft-asset",
|
||||
Tx.contractCall("subnet", "deposit-ft-asset",
|
||||
[
|
||||
types.uint(2),
|
||||
types.principal(charlie.address),
|
||||
@@ -878,7 +878,7 @@ Clarinet.test({
|
||||
|
||||
// User should be able to deposit STX
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-stx",
|
||||
Tx.contractCall("subnet", "deposit-stx",
|
||||
[
|
||||
types.uint(5),
|
||||
types.principal(charlie.address),
|
||||
@@ -891,7 +891,7 @@ Clarinet.test({
|
||||
|
||||
// User should be able to deposit NFT
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-nft-asset",
|
||||
Tx.contractCall("subnet", "deposit-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -938,7 +938,7 @@ Clarinet.test({
|
||||
|
||||
block = chain.mineBlock([
|
||||
// Successfully commit block at height 0 with alice.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash,
|
||||
@@ -952,7 +952,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to withdraw FT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-ft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-ft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(recipient),
|
||||
@@ -982,7 +982,7 @@ Clarinet.test({
|
||||
// Miner should be able to withdraw STX
|
||||
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-stx",
|
||||
Tx.contractCall("subnet", "withdraw-stx",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(recipient),
|
||||
@@ -1008,7 +1008,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to withdraw NFT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(recipient),
|
||||
@@ -1048,7 +1048,7 @@ Clarinet.test({
|
||||
|
||||
// For safety, check that miner can't withdraw FT asset a second time with same key
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-ft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-ft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(recipient),
|
||||
@@ -1078,7 +1078,7 @@ Clarinet.test({
|
||||
|
||||
// For safety, check that miner can't withdraw STX asset a second time with same key
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-stx",
|
||||
Tx.contractCall("subnet", "withdraw-stx",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(recipient),
|
||||
@@ -1105,7 +1105,7 @@ Clarinet.test({
|
||||
|
||||
// For safety, check that miner can't withdraw NFT asset a second time with same key
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(recipient),
|
||||
@@ -1135,14 +1135,14 @@ Clarinet.test({
|
||||
});
|
||||
|
||||
Clarinet.test({
|
||||
name: "Ensure that L1 contract can't mint an NFT first created on the hyperchain if it already exists on the L1",
|
||||
name: "Ensure that L1 contract can't mint an NFT first created on the subnet if it already exists on the L1",
|
||||
async fn(chain: Chain, accounts: Map<string, Account>, contracts: Map<string, Contract>) {
|
||||
|
||||
// miner
|
||||
const alice = accounts.get("wallet_1")!;
|
||||
// user than owns NFT on L1
|
||||
const bob = accounts.get("wallet_2")!;
|
||||
// user that attempts to withdraw NFT minted on the hyperchain to L1
|
||||
// user that attempts to withdraw NFT minted on the subnet to L1
|
||||
const charlie = accounts.get("wallet_3")!;
|
||||
|
||||
// nft contract id
|
||||
@@ -1150,7 +1150,7 @@ Clarinet.test({
|
||||
|
||||
// set alice as a miner
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(alice.address),
|
||||
],
|
||||
@@ -1159,7 +1159,7 @@ Clarinet.test({
|
||||
|
||||
// Miner sets up allowed assets
|
||||
let block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -1186,7 +1186,7 @@ Clarinet.test({
|
||||
|
||||
block = chain.mineBlock([
|
||||
// Successfully commit block at height 0 with alice.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash,
|
||||
@@ -1200,7 +1200,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be not able to withdraw NFT asset since it already exists on the L1
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -1228,7 +1228,7 @@ Clarinet.test({
|
||||
});
|
||||
|
||||
Clarinet.test({
|
||||
name: "Ensure that user can mint an NFT on the hyperchain and L1 miner can withdraw it by minting",
|
||||
name: "Ensure that user can mint an NFT on the subnet and L1 miner can withdraw it by minting",
|
||||
async fn(chain: Chain, accounts: Map<string, Account>, contracts: Map<string, Contract>) {
|
||||
|
||||
// miner
|
||||
@@ -1241,7 +1241,7 @@ Clarinet.test({
|
||||
|
||||
// set alice as a miner
|
||||
let initialize = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(alice.address),
|
||||
],
|
||||
@@ -1250,7 +1250,7 @@ Clarinet.test({
|
||||
|
||||
// Miner sets up allowed assets
|
||||
let block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
alice.address),
|
||||
]);
|
||||
@@ -1270,7 +1270,7 @@ Clarinet.test({
|
||||
|
||||
block = chain.mineBlock([
|
||||
// Successfully commit block at height 0 with alice.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash,
|
||||
@@ -1284,7 +1284,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to withdraw NFT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -1311,7 +1311,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should not be able to withdraw NFT asset a second time
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(charlie.address),
|
||||
@@ -1343,7 +1343,7 @@ Clarinet.test({
|
||||
const nft_contract = contracts.get("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.simple-nft-no-mint")!;
|
||||
|
||||
chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(miner.address),
|
||||
],
|
||||
@@ -1353,7 +1353,7 @@ Clarinet.test({
|
||||
|
||||
// Miner sets up allowed assets
|
||||
let block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
miner.address),
|
||||
]);
|
||||
@@ -1373,7 +1373,7 @@ Clarinet.test({
|
||||
let nft_leaf_hash = fromHex("d95c47532db6bdf22595bbff81ca31a5128417f243988f7da23b917c67c969eb");
|
||||
block = chain.mineBlock([
|
||||
// Successfully commit block at height 0.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash,
|
||||
@@ -1387,7 +1387,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should *not* be able to withdraw NFT asset because the contract doesn't own it.
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(user.address),
|
||||
@@ -1420,7 +1420,7 @@ Clarinet.test({
|
||||
const nft_contract = contracts.get("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.simple-nft-no-mint")!;
|
||||
|
||||
chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(miner.address),
|
||||
],
|
||||
@@ -1439,7 +1439,7 @@ Clarinet.test({
|
||||
|
||||
// Miner sets up allowed assets
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
miner.address),
|
||||
]);
|
||||
@@ -1449,7 +1449,7 @@ Clarinet.test({
|
||||
|
||||
// User should be able to deposit NFT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-nft-asset",
|
||||
Tx.contractCall("subnet", "deposit-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(user.address),
|
||||
@@ -1475,7 +1475,7 @@ Clarinet.test({
|
||||
|
||||
block = chain.mineBlock([
|
||||
// Successfully commit block at height 0.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash,
|
||||
@@ -1490,7 +1490,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to withdraw NFT asset to original user.
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(user.address),
|
||||
@@ -1530,7 +1530,7 @@ Clarinet.test({
|
||||
const nft_contract = contracts.get("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.simple-nft-no-mint")!;
|
||||
|
||||
chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "set-hc-miner",
|
||||
Tx.contractCall("subnet", "set-subnet-miner",
|
||||
[
|
||||
types.principal(miner.address),
|
||||
],
|
||||
@@ -1555,7 +1555,7 @@ Clarinet.test({
|
||||
|
||||
// Miner sets up allowed assets
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "setup-allowed-contracts",
|
||||
Tx.contractCall("subnet", "setup-allowed-contracts",
|
||||
[],
|
||||
miner.address),
|
||||
]);
|
||||
@@ -1565,7 +1565,7 @@ Clarinet.test({
|
||||
|
||||
// User should be able to deposit NFT asset
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "deposit-nft-asset",
|
||||
Tx.contractCall("subnet", "deposit-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(original_user.address),
|
||||
@@ -1594,7 +1594,7 @@ Clarinet.test({
|
||||
const id_header_hash = chain.callReadOnlyFn('test-helpers', 'get-id-header-hash', [], miner.address).result.expectOk().toString();
|
||||
block = chain.mineBlock([
|
||||
// Successfully commit block at height 0.
|
||||
Tx.contractCall("hyperchains", "commit-block",
|
||||
Tx.contractCall("subnet", "commit-block",
|
||||
[
|
||||
types.buff(new Uint8Array([0, 1, 1, 1, 1])),
|
||||
id_header_hash,
|
||||
@@ -1608,7 +1608,7 @@ Clarinet.test({
|
||||
|
||||
// Miner should be able to withdraw NFT asset to other_user.
|
||||
block = chain.mineBlock([
|
||||
Tx.contractCall("hyperchains", "withdraw-nft-asset",
|
||||
Tx.contractCall("subnet", "withdraw-nft-asset",
|
||||
[
|
||||
types.uint(1),
|
||||
types.principal(other_user.address),
|
||||
Reference in New Issue
Block a user