From 0874d7db246d093f7141ec55f251668ce596288a Mon Sep 17 00:00:00 2001 From: olgaklimenko Date: Sun, 21 Nov 2021 10:42:48 +0700 Subject: [PATCH 1/7] update deps to 7333e3c3ae --- MetaLamp/nft-marketplace/cabal.project | 2 +- MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix | 2 +- MetaLamp/nft-marketplace/nix/sources.json | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MetaLamp/nft-marketplace/cabal.project b/MetaLamp/nft-marketplace/cabal.project index be1d0c6fe..ff08d0586 100644 --- a/MetaLamp/nft-marketplace/cabal.project +++ b/MetaLamp/nft-marketplace/cabal.project @@ -26,7 +26,7 @@ source-repository-package plutus-use-cases quickcheck-dynamic web-ghc - tag: v2021-11-05 + tag: 7333e3c3ae62c955c5db7799dbf1c1f58593325d -- The following sections are copied from the 'plutus-apps' repository cabal.project at the revision diff --git a/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix b/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix index 1b6ce59ae..0e5f6bf2f 100644 --- a/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix +++ b/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix @@ -19,7 +19,7 @@ let inherit compiler-nix-name; sha256map = { - "https://github.com/input-output-hk/plutus-apps.git"."v2021-11-05" = "00pv5ds99lf6lmws3a3ipsn9amg56ayc9b0wqki2gky464dm6gzr"; + "https://github.com/input-output-hk/plutus-apps.git"."7333e3c3ae62c955c5db7799dbf1c1f58593325d" = "1j5wwi9q71gbsakcvq67phpi4nha643aw711c0zyfjs5sd2r5hzb"; "https://github.com/Quid2/flat.git"."ee59880f47ab835dbd73bea0847dab7869fc20d8" = "1lrzknw765pz2j97nvv9ip3l1mcpf2zr4n56hwlz0rk7wq7ls4cm"; "https://github.com/input-output-hk/purescript-bridge.git"."366fc70b341e2633f3ad0158a577d52e1cd2b138" = "18j0rysfccbmfpbw2d1rsjkpd5h84alpsn6b5rwzdxw9h5vqi9m5"; "https://github.com/input-output-hk/servant-purescript.git"."ebea59c7bdfc0338d83fca772b9a57e28560bcde" = "0gjcq4y61kwb4w70pnswn5dp23wd13dac8d9hz84j374cm1kshsn"; diff --git a/MetaLamp/nft-marketplace/nix/sources.json b/MetaLamp/nft-marketplace/nix/sources.json index cbee24ba0..52d2cc97a 100644 --- a/MetaLamp/nft-marketplace/nix/sources.json +++ b/MetaLamp/nft-marketplace/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "", "owner": "input-output-hk", "repo": "plutus-apps", - "rev": "v2021-11-05", - "sha256": "00pv5ds99lf6lmws3a3ipsn9amg56ayc9b0wqki2gky464dm6gzr", + "rev": "7333e3c3ae62c955c5db7799dbf1c1f58593325d", + "sha256": "1j5wwi9q71gbsakcvq67phpi4nha643aw711c0zyfjs5sd2r5hzb", "type": "tarball", - "url": "https://github.com/input-output-hk/plutus-apps/archive/v2021-11-05.tar.gz", + "url": "https://github.com/input-output-hk/plutus-apps/archive/7333e3c3ae62c955c5db7799dbf1c1f58593325d.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } \ No newline at end of file From d6420e000bf71cf189c4310d44b47eeb9c8ebcf2 Mon Sep 17 00:00:00 2001 From: olgaklimenko Date: Mon, 22 Nov 2021 13:04:40 +0700 Subject: [PATCH 2/7] remove unused deps from haskell.nix --- MetaLamp/nft-marketplace/config/plutus-pab.template.yaml | 2 +- MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/MetaLamp/nft-marketplace/config/plutus-pab.template.yaml b/MetaLamp/nft-marketplace/config/plutus-pab.template.yaml index 93144ee88..e622717bd 100644 --- a/MetaLamp/nft-marketplace/config/plutus-pab.template.yaml +++ b/MetaLamp/nft-marketplace/config/plutus-pab.template.yaml @@ -22,7 +22,7 @@ nodeServerConfig: mscKeptBlocks: 100 mscNetworkId: "1097911063" # Testnet network ID (main net = empty string) mscSlotConfig: - scSlotZeroTime: 1591566291000 # Wednesday, July 29, 2020 21:44:51 - shelley launch time in milliseconds + scSlotZeroTime: 1596059091000 # Wednesday, July 29, 2020 21:44:51 - shelley launch time in milliseconds scSlotLength: 1000 # In milliseconds mscFeeConfig: fcConstantFee: diff --git a/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix b/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix index 0e5f6bf2f..82d292729 100644 --- a/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix +++ b/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix @@ -34,7 +34,6 @@ let "https://github.com/input-output-hk/cardano-node.git"."b6ca519f97a0e795611a63174687e6bb70c9f752" = "0z5lpmqc98fwg3xzpzxkfslbxdjwfyyw8bn8yq0574sf4942vqdn"; "https://github.com/input-output-hk/Win32-network"."3825d3abf75f83f406c1f7161883c438dac7277d" = "19wahfv726fa3mqajpqdqhnl9ica3xmf68i254q45iyjcpj1psqx"; "https://github.com/input-output-hk/hedgehog-extras"."edf6945007177a638fbeb8802397f3a6f4e47c14" = "0wc7qzkc7j4ns2rz562h6qrx2f8xyq7yjcb7zidnj7f6j0pcd0i9"; - "https://github.com/input-output-hk/cardano-wallet"."ae7569293e94241ef6829139ec02bd91abd069df" = "1mv1dhpkdj9ridm1fvq6jc85qs6zvbp172228rq72gyawjwrgvi6"; "https://github.com/input-output-hk/cardano-addresses"."d2f86caa085402a953920c6714a0de6a50b655ec" = "0p6jbnd7ky2yf7bwb1350k8880py8dgqg39k49q02a6ij4ld01ay"; "https://github.com/input-output-hk/plutus"."3f089ccf0ca746b399c99afe51e063b0640af547" = "1nx8xmdgwmnsla4qg4k67f5md8vm3p1p9i25ndalrqdg40z90486"; "https://github.com/j-mueller/cardano-wallet"."6be73ab852c0592713dfe78218856d4a8a0ee69e" = "0rx5hvmbdv5dwb4qq39vyhisj0v75j21jbiivn3s3q9za6m6x1p4"; From c81c7f3c4544d9cc80b04447c3a590c8e755d1b7 Mon Sep 17 00:00:00 2001 From: olgaklimenko Date: Mon, 22 Nov 2021 16:06:23 +0700 Subject: [PATCH 3/7] add min-ada-value on start marketplace --- .../nft-marketplace/src/Ext/Plutus/Ledger/Value.hs | 11 +++++++++++ .../Plutus/Contracts/NftMarketplace/OffChain/Owner.hs | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Value.hs b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Value.hs index fed38275a..a9ed5cba3 100644 --- a/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Value.hs +++ b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Value.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE NumericUnderscores #-} module Ext.Plutus.Ledger.Value where import Control.Lens (view) @@ -9,6 +10,7 @@ import Ledger.AddressMap (UtxoMap) import Ledger.Tx (ChainIndexTxOut, ciTxOutValue, toTxOut) import Plutus.Contract import Plutus.V1.Ledger.Value (Value) +import Plutus.V1.Ledger.Ada (lovelaceValueOf, fromValue, toValue) type ChainIndexTxMap = Map.Map TxOutRef ChainIndexTxOut @@ -16,3 +18,12 @@ utxosValue :: Address -> Contract w s Text Value utxosValue address = do os <- map snd . Map.toList <$> utxosAt address return $ mconcat [view ciTxOutValue o | o <- os] + +-- TODO: Make that configurable: +-- Read minUTxOValue from `testnet-shelley-genesis.json` cardano-node config +minAdaValue :: Value +minAdaValue = lovelaceValueOf 1_000_000 + +withMinAdaValue :: Value -> Value +withMinAdaValue initialValue = + toValue (fromValue initialValue + fromValue minAdaValue) \ No newline at end of file diff --git a/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs b/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs index b1be1dedb..be48d01bd 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs @@ -39,6 +39,8 @@ import Prelude (Semigroup (..)) import qualified Prelude as Haskell import qualified Schema import Text.Printf (printf) +import Plutus.V1.Ledger.Ada (lovelaceValueOf) +import Ext.Plutus.Ledger.Value (minAdaValue) data StartMarketplaceParams = StartMarketplaceParams { creationFee :: Integer, -- fee by minting and bundling @@ -54,7 +56,7 @@ start StartMarketplaceParams {..} = do saleFeePercentage <- maybe (throwError "Operator's fee value should be in [0, 100]") pure $ mkPercentage saleFee let marketplace = Core.Marketplace pkh (Lovelace creationFee) saleFeePercentage let client = Core.marketplaceClient marketplace - void $ mapError (T.pack . Haskell.show @SMContractError) $ runInitialise client (Core.MarketplaceDatum AssocMap.empty AssocMap.empty) mempty + void $ mapError (T.pack . Haskell.show @SMContractError) $ runInitialise client (Core.MarketplaceDatum AssocMap.empty AssocMap.empty) minAdaValue logInfo @Haskell.String $ printf "started Marketplace %s at address %s" (Haskell.show marketplace) (Haskell.show $ Core.marketplaceAddress marketplace) pure marketplace From 98ed5b807c1e27c93a0c052cc2f69c66bb7c91dc Mon Sep 17 00:00:00 2001 From: olgaklimenko Date: Tue, 23 Nov 2021 10:24:00 +0700 Subject: [PATCH 4/7] update to v2021-11-22 --- MetaLamp/nft-marketplace/cabal.project | 2 +- MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix | 2 +- MetaLamp/nft-marketplace/nix/sources.json | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MetaLamp/nft-marketplace/cabal.project b/MetaLamp/nft-marketplace/cabal.project index ff08d0586..3881ae532 100644 --- a/MetaLamp/nft-marketplace/cabal.project +++ b/MetaLamp/nft-marketplace/cabal.project @@ -26,7 +26,7 @@ source-repository-package plutus-use-cases quickcheck-dynamic web-ghc - tag: 7333e3c3ae62c955c5db7799dbf1c1f58593325d + tag: v2021-11-22 -- The following sections are copied from the 'plutus-apps' repository cabal.project at the revision diff --git a/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix b/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix index 82d292729..d6401f530 100644 --- a/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix +++ b/MetaLamp/nft-marketplace/nix/pkgs/haskell/haskell.nix @@ -19,7 +19,7 @@ let inherit compiler-nix-name; sha256map = { - "https://github.com/input-output-hk/plutus-apps.git"."7333e3c3ae62c955c5db7799dbf1c1f58593325d" = "1j5wwi9q71gbsakcvq67phpi4nha643aw711c0zyfjs5sd2r5hzb"; + "https://github.com/input-output-hk/plutus-apps.git"."v2021-11-22" = "10m0gmnakjnpnzyvjs3ksfpxgjcq3pdphr4gf8v7fjhr9fjbc45n"; "https://github.com/Quid2/flat.git"."ee59880f47ab835dbd73bea0847dab7869fc20d8" = "1lrzknw765pz2j97nvv9ip3l1mcpf2zr4n56hwlz0rk7wq7ls4cm"; "https://github.com/input-output-hk/purescript-bridge.git"."366fc70b341e2633f3ad0158a577d52e1cd2b138" = "18j0rysfccbmfpbw2d1rsjkpd5h84alpsn6b5rwzdxw9h5vqi9m5"; "https://github.com/input-output-hk/servant-purescript.git"."ebea59c7bdfc0338d83fca772b9a57e28560bcde" = "0gjcq4y61kwb4w70pnswn5dp23wd13dac8d9hz84j374cm1kshsn"; diff --git a/MetaLamp/nft-marketplace/nix/sources.json b/MetaLamp/nft-marketplace/nix/sources.json index 52d2cc97a..2d3e32c68 100644 --- a/MetaLamp/nft-marketplace/nix/sources.json +++ b/MetaLamp/nft-marketplace/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "", "owner": "input-output-hk", "repo": "plutus-apps", - "rev": "7333e3c3ae62c955c5db7799dbf1c1f58593325d", - "sha256": "1j5wwi9q71gbsakcvq67phpi4nha643aw711c0zyfjs5sd2r5hzb", + "rev": "v2021-11-22", + "sha256": "10m0gmnakjnpnzyvjs3ksfpxgjcq3pdphr4gf8v7fjhr9fjbc45n", "type": "tarball", - "url": "https://github.com/input-output-hk/plutus-apps/archive/7333e3c3ae62c955c5db7799dbf1c1f58593325d.tar.gz", + "url": "https://github.com/input-output-hk/plutus-apps/archive/v2021-11-22.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } \ No newline at end of file From 83d3e2f159be22fcf0c35cef240dd90690c009a0 Mon Sep 17 00:00:00 2001 From: olgaklimenko Date: Tue, 23 Nov 2021 18:32:54 +0700 Subject: [PATCH 5/7] fix tests --- MetaLamp/nft-marketplace/plutus-starter.cabal | 1 + .../src/Ext/Plutus/Ledger/Index.hs | 13 +++ .../src/Ext/Plutus/Ledger/Value.hs | 10 -- .../src/Plutus/Abstract/Percentage.hs | 1 + .../NftMarketplace/OffChain/Owner.hs | 4 +- MetaLamp/nft-marketplace/test/Main.hs | 4 +- .../test/Marketplace/Fixtures/Script.hs | 13 ++- .../test/Marketplace/Spec/Auction.hs | 49 +++++--- .../test/Marketplace/Spec/Bundles.hs | 16 +-- .../test/Marketplace/Spec/CreateNft.hs | 13 ++- .../test/Marketplace/Spec/Sale.hs | 105 +++++++++++------- .../test/Marketplace/Spec/Start.hs | 15 ++- 12 files changed, 155 insertions(+), 89 deletions(-) create mode 100644 MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs diff --git a/MetaLamp/nft-marketplace/plutus-starter.cabal b/MetaLamp/nft-marketplace/plutus-starter.cabal index 61a3aa69b..3d63dfb35 100644 --- a/MetaLamp/nft-marketplace/plutus-starter.cabal +++ b/MetaLamp/nft-marketplace/plutus-starter.cabal @@ -41,6 +41,7 @@ common lang library import: lang exposed-modules: + Ext.Plutus.Ledger.Index Ext.Plutus.Ledger.Time Ext.Plutus.Ledger.Value Ext.Plutus.PAB.Webserver.Server diff --git a/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs new file mode 100644 index 000000000..45ca7e53c --- /dev/null +++ b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs @@ -0,0 +1,13 @@ +module Ext.Plutus.Ledger.Index where + +import Ledger.Index (minAdaTxOut) +import Plutus.V1.Ledger.Value (Value) +import Plutus.V1.Ledger.Ada (Ada, lovelaceValueOf, fromValue, toValue) + +-- TODO: That should be configurable in future: +-- Read minUTxOValue from `testnet-shelley-genesis.json` cardano-node config +minAdaTxOutValue :: Value +minAdaTxOutValue = toValue minAdaTxOut + +withMinAdaTxOutValue :: Ada -> Value +withMinAdaTxOutValue initialTxOut = toValue (initialTxOut + minAdaTxOut) diff --git a/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Value.hs b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Value.hs index a9ed5cba3..4acccdba2 100644 --- a/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Value.hs +++ b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Value.hs @@ -10,7 +10,6 @@ import Ledger.AddressMap (UtxoMap) import Ledger.Tx (ChainIndexTxOut, ciTxOutValue, toTxOut) import Plutus.Contract import Plutus.V1.Ledger.Value (Value) -import Plutus.V1.Ledger.Ada (lovelaceValueOf, fromValue, toValue) type ChainIndexTxMap = Map.Map TxOutRef ChainIndexTxOut @@ -18,12 +17,3 @@ utxosValue :: Address -> Contract w s Text Value utxosValue address = do os <- map snd . Map.toList <$> utxosAt address return $ mconcat [view ciTxOutValue o | o <- os] - --- TODO: Make that configurable: --- Read minUTxOValue from `testnet-shelley-genesis.json` cardano-node config -minAdaValue :: Value -minAdaValue = lovelaceValueOf 1_000_000 - -withMinAdaValue :: Value -> Value -withMinAdaValue initialValue = - toValue (fromValue initialValue + fromValue minAdaValue) \ No newline at end of file diff --git a/MetaLamp/nft-marketplace/src/Plutus/Abstract/Percentage.hs b/MetaLamp/nft-marketplace/src/Plutus/Abstract/Percentage.hs index 3ff22da4e..c44dc2346 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Abstract/Percentage.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Abstract/Percentage.hs @@ -31,3 +31,4 @@ mkPercentage percentage@(numerator, denominator) = if denominator /= 0 && 0 <= roundedPercentage && roundedPercentage <= 100 then pure $ Percentage percentage else Nothing + diff --git a/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs b/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs index be48d01bd..1c59a1066 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs @@ -40,7 +40,7 @@ import qualified Prelude as Haskell import qualified Schema import Text.Printf (printf) import Plutus.V1.Ledger.Ada (lovelaceValueOf) -import Ext.Plutus.Ledger.Value (minAdaValue) +import Ext.Plutus.Ledger.Index (minAdaTxOutValue) data StartMarketplaceParams = StartMarketplaceParams { creationFee :: Integer, -- fee by minting and bundling @@ -56,7 +56,7 @@ start StartMarketplaceParams {..} = do saleFeePercentage <- maybe (throwError "Operator's fee value should be in [0, 100]") pure $ mkPercentage saleFee let marketplace = Core.Marketplace pkh (Lovelace creationFee) saleFeePercentage let client = Core.marketplaceClient marketplace - void $ mapError (T.pack . Haskell.show @SMContractError) $ runInitialise client (Core.MarketplaceDatum AssocMap.empty AssocMap.empty) minAdaValue + void $ mapError (T.pack . Haskell.show @SMContractError) $ runInitialise client (Core.MarketplaceDatum AssocMap.empty AssocMap.empty) minAdaTxOutValue logInfo @Haskell.String $ printf "started Marketplace %s at address %s" (Haskell.show marketplace) (Haskell.show $ Core.marketplaceAddress marketplace) pure marketplace diff --git a/MetaLamp/nft-marketplace/test/Main.hs b/MetaLamp/nft-marketplace/test/Main.hs index 03c58bcd0..12bd6da7a 100644 --- a/MetaLamp/nft-marketplace/test/Main.hs +++ b/MetaLamp/nft-marketplace/test/Main.hs @@ -20,6 +20,6 @@ tests = "All tests" [ testGroup "NFT Marketplace" - [Start.tests, CreateNft.tests, Bundles.tests, Sale.tests, Auction.tests] - , testGroup "Abstract" [RemoteData.tests, Percentage.tests] + [Start.tests, CreateNft.tests, Bundles.tests, Auction.tests] -- , Sale.tests] + -- , testGroup "Abstract" [RemoteData.tests, Percentage.tests] ] diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Fixtures/Script.hs b/MetaLamp/nft-marketplace/test/Marketplace/Fixtures/Script.hs index 4e2b00d01..a39f5e668 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Fixtures/Script.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Fixtures/Script.hs @@ -1,6 +1,6 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} - +{-# LANGUAGE NumericUnderscores #-} module Marketplace.Fixtures.Script where import Ledger (Address, @@ -13,17 +13,24 @@ import Plutus.Abstract.Percentage (Percentage (..)) import qualified Plutus.Contracts.NftMarketplace.OnChain.Core as Marketplace import Wallet.Emulator.Types (Wallet (..), walletPubKeyHash) +import Plutus.Abstract.PercentageInterface (calculatePercentageRounded) marketplace :: Marketplace.Marketplace marketplace = Marketplace.Marketplace { Marketplace.marketplaceOperator = walletPubKeyHash Fixtures.ownerWallet, Marketplace.marketplaceSaleFee = percentage, - Marketplace.marketplaceNFTFee = Lovelace 100000 -- 0.1 ADA + Marketplace.marketplaceNFTFee = marketplaceCreationFee } +marketplaceCreationFee :: Ada +marketplaceCreationFee = Lovelace 2_100_000 -- 2.1 ADA (should be gte then minAdaTxOut) + percentage :: Percentage -percentage = Percentage (5, 2) +percentage = Percentage (7, 2) + +roundedPercentage :: Integer -> Integer +roundedPercentage price = calculatePercentageRounded percentage price marketplaceAddress :: Address marketplaceAddress = Marketplace.marketplaceAddress marketplace diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Auction.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Auction.hs index 43daa91e0..34812328d 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Auction.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Auction.hs @@ -18,7 +18,6 @@ import Data.Void (Void) import Ext.Plutus.Ledger.Time (Seconds (..), addToBeginningOfTime) import Ledger (Value) -import Ledger.Ada (lovelaceValueOf) import qualified Ledger.Value as V import qualified Marketplace.Fixtures as Fixtures import qualified Marketplace.Spec.Bundles as Bundles @@ -37,6 +36,10 @@ import qualified PlutusTx.AssocMap as AssocMap import Test.Tasty import qualified Utils import Wallet.Emulator.Wallet (walletAddress) +import Ledger.Ada (Ada(..), toValue, lovelaceValueOf) +import Ledger.Index (minAdaTxOut) + + tests :: TestTree tests = testGroup @@ -158,10 +161,14 @@ closeLotParams :: Marketplace.CloseLotParams closeLotParams = Marketplace.CloseLotParams { Marketplace.clpItemId = Marketplace.UserNftId Fixtures.catTokenIpfsCid } + +highestBid :: Integer +highestBid = 75 * Fixtures.oneAdaInLovelace + bidOnAuctionParams :: Marketplace.BidOnAuctionParams bidOnAuctionParams = Marketplace.BidOnAuctionParams { Marketplace.boapItemId = Marketplace.UserNftId Fixtures.catTokenIpfsCid, - Marketplace.boapBid = fromInteger $ 25 * Fixtures.oneAdaInLovelace + Marketplace.boapBid = fromInteger $ 75 * Fixtures.oneAdaInLovelace } startAnAuctionTrace :: Trace.EmulatorTrace (Trace.ContractHandle (ContractResponse String Text Marketplace.UserContractState) Marketplace.MarketplaceUserSchema Void) @@ -353,10 +360,13 @@ closeLotParamsB = Marketplace.CloseLotParams { Marketplace.clpItemId = Marketplace.UserBundleId Fixtures.cids } +highestBidB :: Integer +highestBidB = 95 * Fixtures.oneAdaInLovelace + bidOnAuctionParamsB :: Marketplace.BidOnAuctionParams bidOnAuctionParamsB = Marketplace.BidOnAuctionParams { Marketplace.boapItemId = Marketplace.UserBundleId Fixtures.cids, - Marketplace.boapBid = fromInteger $ 35 * Fixtures.oneAdaInLovelace + Marketplace.boapBid = fromInteger highestBidB } startAnAuctionTraceB :: Trace.EmulatorTrace (Trace.ContractHandle (ContractResponse String Text Marketplace.UserContractState) Marketplace.MarketplaceUserSchema Void) @@ -495,23 +505,34 @@ buyOnAuctionValueCheckB = marketplaceOperatorFeeCheck :: TracePredicate marketplaceOperatorFeeCheck = - walletFundsChange Fixtures.ownerWallet $ lovelaceValueOf 725000 - -- 25000000 * 2.5 /100 = 625000 - fee by complete auction - -- 100000 - fee by minting token + walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + auctionFee - minAdaTxOut) + where + totalMintingFee = Fixtures.marketplaceCreationFee + auctionFee = Lovelace $ Fixtures.roundedPercentage highestBid sellerProfitWithFeeCheck :: TracePredicate sellerProfitWithFeeCheck = - walletFundsChange Fixtures.userWallet $ lovelaceValueOf 24275000 - -- 25000000 - 725000 = 24275000 + walletFundsChange Fixtures.userWallet $ toValue (highestBidAda - totalMintingFee - openAuctionMinAdaTxOut - auctionFee) + where + totalMintingFee = Fixtures.marketplaceCreationFee + auctionFee = Lovelace $ Fixtures.roundedPercentage highestBid + highestBidAda = Lovelace highestBid + openAuctionMinAdaTxOut = minAdaTxOut marketplaceOperatorFeeCheckB :: TracePredicate marketplaceOperatorFeeCheckB = - walletFundsChange Fixtures.ownerWallet $ lovelaceValueOf 1175000 - -- 35000000 * 2.5 /100 = 875000 - fee by complete auction - -- 100000 * 2 = 200000 - fee by minting 2 tokens - -- 100000 - fee by bundling + walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + totalBundlingFee + auctionFee - minAdaTxOut) + where + totalMintingFee = Fixtures.marketplaceCreationFee * 2 + totalBundlingFee = Fixtures.marketplaceCreationFee + auctionFee = Lovelace $ Fixtures.roundedPercentage highestBidB sellerProfitWithFeeCheckB :: TracePredicate sellerProfitWithFeeCheckB = - walletFundsChange Fixtures.userWallet $ lovelaceValueOf 33825000 - -- 35000000 - 1175000 = 33825000 + walletFundsChange Fixtures.userWallet $ toValue (highestBidAda - totalMintingFee - totalBundlingFee - openAuctionMinAdaTxOut - auctionFee) + where + totalMintingFee = Fixtures.marketplaceCreationFee * 2 + totalBundlingFee = Fixtures.marketplaceCreationFee + auctionFee = Lovelace $ Fixtures.roundedPercentage highestBidB + highestBidAda = Lovelace highestBidB + openAuctionMinAdaTxOut = minAdaTxOut diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Bundles.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Bundles.hs index 629a9eb1e..87a1d9fad 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Bundles.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Bundles.hs @@ -13,7 +13,7 @@ import Data.Maybe (isNothing) import Data.Proxy import Data.Text (Text) import Data.Void (Void) -import Ledger.Ada (lovelaceValueOf) +import Ledger.Ada (toValue) import qualified Marketplace.Fixtures as Fixtures import qualified Marketplace.Spec.Start as Start import Plutus.Abstract.ContractResponse (ContractResponse) @@ -24,6 +24,7 @@ import qualified Plutus.Trace as Trace import qualified PlutusTx.AssocMap as AssocMap import Test.Tasty import qualified Utils +import Ledger.Index (minAdaTxOut) tests :: TestTree tests = @@ -33,7 +34,7 @@ tests = checkPredicateOptions Fixtures.options "Should create a bundle for two NFTs transforming Marketplace store" - (bundleDatumsCheck .&&. marketplaceOperatorFeeCheck) + (bundleDatumsCheck .&&. marketplaceOperatorFundsCheck) (void bundleTrace), checkPredicateOptions Fixtures.options @@ -150,8 +151,9 @@ unbundleDatumsCheck = maybe False (Fixtures.hasPhotoTokenRecord . Marketplace.nftRecord) (AssocMap.lookup Fixtures.photoTokenIpfsCidHash store) -marketplaceOperatorFeeCheck :: TracePredicate -marketplaceOperatorFeeCheck = - walletFundsChange Fixtures.ownerWallet $ lovelaceValueOf 300000 --- 100000 * 2 = 200000 - fee by minting 2 tokens --- 100000 - fee by bundling +marketplaceOperatorFundsCheck :: TracePredicate +marketplaceOperatorFundsCheck = + walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + totalBundlingFee - minAdaTxOut) + where + totalBundlingFee = Fixtures.marketplaceCreationFee + totalMintingFee = Fixtures.marketplaceCreationFee * 2 \ No newline at end of file diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/CreateNft.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/CreateNft.hs index 0b260a6bc..90b99a46f 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/CreateNft.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/CreateNft.hs @@ -13,7 +13,7 @@ import Control.Monad (void) import Data.Maybe (isNothing) import Data.Text (Text) import Data.Void (Void) -import Ledger.Ada (lovelaceValueOf) +import Ledger.Ada (toValue) import qualified Ledger.Value as V import qualified Marketplace.Fixtures as Fixtures import qualified Marketplace.Spec.Start as Start @@ -27,6 +27,7 @@ import Test.Tasty import qualified Utils import Wallet.Emulator.Wallet (walletAddress, walletPubKeyHash) +import Ledger.Index (minAdaTxOut) tests :: TestTree tests = @@ -35,12 +36,12 @@ tests = [ checkPredicateOptions Fixtures.options "Should mint NFT token into the user wallet and create the Marketplace entry hiding issuer" - (datumsCheck .&&. valueCheck .&&. marketplaceOperatorFeeCheck) + (datumsCheck .&&. valueCheck .&&. marketplaceOperatorFundsCheck) (void createNftTrace), checkPredicateOptions Fixtures.options "Should mint NFT token into the user wallet and create the Marketplace entry revealing issuer" - (datumsCheck' .&&. valueCheck .&&. marketplaceOperatorFeeCheck) + (datumsCheck' .&&. valueCheck .&&. marketplaceOperatorFundsCheck) createNftTrace' ] @@ -99,6 +100,6 @@ valueCheck = where hasNft v = (v ^. _2 & V.unTokenName) == Fixtures.catTokenIpfsCidBs -marketplaceOperatorFeeCheck :: TracePredicate -marketplaceOperatorFeeCheck = - walletFundsChange Fixtures.ownerWallet $ lovelaceValueOf 100000 +marketplaceOperatorFundsCheck :: TracePredicate +marketplaceOperatorFundsCheck = + walletFundsChange Fixtures.ownerWallet $ toValue (Fixtures.marketplaceCreationFee - minAdaTxOut) diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs index 399b9b1c4..a726232b4 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs @@ -31,6 +31,8 @@ import qualified PlutusTx.AssocMap as AssocMap import Test.Tasty import qualified Utils import Wallet.Emulator.Wallet (walletAddress) +import Ledger.Ada (Ada(..), toValue) +import Ledger.Index (minAdaTxOut) tests :: TestTree tests = @@ -68,48 +70,52 @@ tests = Fixtures.options "Should not sell NFT if it has no lot" errorCheckBuyer - buyItemTrace', - checkPredicateOptions - Fixtures.options - "Should sell NFT and pay fee to marketplace operator" - (marketplaceOperatorFeeCheck .&&. sellersProfitWithPayingFeeCheck) - buyItemTrace - ], - testGroup - "NFT bundles" - [ - checkPredicateOptions - Fixtures.options - "Should put on sale NFT bundle locking bundle value in sale script & saving link" - (openSaleValueCheckB .&&. openSaleDatumsCheckB) - (void openSaleTraceB), - checkPredicateOptions - Fixtures.options - "Should not put on sale if bundle does not exist" - errorCheckOpen - openSaleTraceB', - checkPredicateOptions - Fixtures.options - "Should close sale and pay locked bundle value back" - (closeSaleValueCheckB .&&. completeSaleDatumsCheckB) - closeSaleTraceB, - checkPredicateOptions - Fixtures.options - "Should sell bundle and pay its value to buyer" - (buyItemValueCheckB .&&. completeSaleDatumsCheckB) - buyItemTraceB, - checkPredicateOptions - Fixtures.options - "Should sell bundle and pay fee to marketplace operator" - (marketplaceOperatorFeeCheckB .&&. sellersProfitWithPayingFeeCheckB) - buyItemTraceB + buyItemTrace' + -- checkPredicateOptions + -- Fixtures.options + -- "Should sell NFT and pay fee to marketplace operator" + -- (marketplaceOperatorFeeCheck .&&. sellersProfitWithPayingFeeCheck) + -- buyItemTrace ]] + -- , + -- testGroup + -- "NFT bundles" + -- [ + -- checkPredicateOptions + -- Fixtures.options + -- "Should put on sale NFT bundle locking bundle value in sale script & saving link" + -- (openSaleValueCheckB .&&. openSaleDatumsCheckB) + -- (void openSaleTraceB), + -- checkPredicateOptions + -- Fixtures.options + -- "Should not put on sale if bundle does not exist" + -- errorCheckOpen + -- openSaleTraceB', + -- checkPredicateOptions + -- Fixtures.options + -- "Should close sale and pay locked bundle value back" + -- (closeSaleValueCheckB .&&. completeSaleDatumsCheckB) + -- closeSaleTraceB, + -- checkPredicateOptions + -- Fixtures.options + -- "Should sell bundle and pay its value to buyer" + -- (buyItemValueCheckB .&&. completeSaleDatumsCheckB) + -- buyItemTraceB, + -- checkPredicateOptions + -- Fixtures.options + -- "Should sell bundle and pay fee to marketplace operator" + -- (marketplaceOperatorFeeCheckB .&&. sellersProfitWithPayingFeeCheckB) + -- buyItemTraceB + -- ]] + +singletonNftPrice :: Integer +singletonNftPrice = 60 * Fixtures.oneAdaInLovelace -- \/\/\/ "NFT singletons" openSaleParams :: Marketplace.OpenSaleParams openSaleParams = Marketplace.OpenSaleParams { Marketplace.ospItemId = Marketplace.UserNftId Fixtures.catTokenIpfsCid, - Marketplace.ospSalePrice = 44 * Fixtures.oneAdaInLovelace + Marketplace.ospSalePrice = singletonNftPrice } closeLotParams :: Marketplace.CloseLotParams @@ -324,21 +330,34 @@ buyItemValueCheckB = marketplaceOperatorFeeCheck :: TracePredicate marketplaceOperatorFeeCheck = - walletFundsChange Fixtures.ownerWallet $ lovelaceValueOf 1200000 - -- 44000000 * 2.5 /100 = 1100000 - fee by complete sale - -- 100000 - fee by minting token + walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + saleFee - minAdaTxOut) + -- 60_000_000 * 3.5 /100 = 2_100_000 - fee by complete sale + -- 2_100_000 - fee by minting token + -- 2_000_000 - minAdaTxOut by starting marketplace + -- (2_100_000 + 2_100_000 - 2_000_000) = 2_200_000 + where + totalMintingFee = Fixtures.marketplaceCreationFee + saleFee = Lovelace $ Fixtures.roundedPercentage singletonNftPrice sellersProfitWithPayingFeeCheck :: TracePredicate sellersProfitWithPayingFeeCheck = - walletFundsChange Fixtures.userWallet $ lovelaceValueOf 42800000 + walletFundsChange Fixtures.userWallet $ toValue (nftPriceAda - saleFee - totalMintingFee) -- 44000000 - 1200000 = 42800000 - seller's profit + where + saleFee = Lovelace $ Fixtures.roundedPercentage singletonNftPrice + totalMintingFee = Fixtures.marketplaceCreationFee + nftPriceAda = Lovelace singletonNftPrice marketplaceOperatorFeeCheckB :: TracePredicate marketplaceOperatorFeeCheckB = walletFundsChange Fixtures.ownerWallet $ lovelaceValueOf 1925000 - -- 65000000 * 2.5 /100 = 1625000 - fee by complete sale - -- 100000 * 2 = 200000 - fee by minting 2 tokens - -- 100000 - fee by bundling + -- 65_000_000 * 3.5 /100 = 1_625_000 - fee by complete sale + -- 100_000 * 2 = 200000 - fee by minting 2 tokens + -- 100_000 - fee by bundling + where + totalMintingFee = Fixtures.marketplaceCreationFee * 2 + totalBundlingFee = Fixtures.marketplaceCreationFee + sellersProfitWithPayingFeeCheckB :: TracePredicate sellersProfitWithPayingFeeCheckB = diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Start.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Start.hs index c41e29d41..433184261 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Start.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Start.hs @@ -1,5 +1,6 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE NumericUnderscores #-} module Marketplace.Spec.Start ( tests, startTrace @@ -18,6 +19,8 @@ import qualified Plutus.Contracts.NftMarketplace.OnChain.Core as Marketplace import qualified Plutus.Trace as Trace import qualified PlutusTx.AssocMap as AssocMap import Test.Tasty +import Ledger.Ada (toValue, Ada(..)) +import Ledger.Index (minAdaTxOut) tests :: TestTree tests = @@ -26,7 +29,7 @@ tests = [ checkPredicateOptions Fixtures.options "Should start a new marketplace with empty store" - datumsCheck + (datumsCheck .&&. marketplaceOpenedWithMinAdaTxOut .&&. marketplaceOperatorPayedMinAdaTxOut) startTrace ] @@ -38,7 +41,7 @@ startTrace = do startMarketplaceParams :: StartMarketplaceParams startMarketplaceParams = StartMarketplaceParams { - creationFee = 100000, -- 0.1 ADA + creationFee = getLovelace $ Fixtures.marketplaceCreationFee, saleFee = getPercentage Fixtures.percentage } @@ -51,3 +54,11 @@ datumsCheck = dataAtAddress Fixtures.marketplaceAddress (== [Marketplace.MarketplaceDatum AssocMap.empty AssocMap.empty]) + +marketplaceOpenedWithMinAdaTxOut :: TracePredicate +marketplaceOpenedWithMinAdaTxOut = + valueAtAddress Fixtures.marketplaceAddress (toValue minAdaTxOut ==) + +marketplaceOperatorPayedMinAdaTxOut :: TracePredicate +marketplaceOperatorPayedMinAdaTxOut = + walletFundsChange Fixtures.ownerWallet $ toValue (- minAdaTxOut) From f3297847c2dde802ec89d7cd2983b86b964e7ed7 Mon Sep 17 00:00:00 2001 From: olgaklimenko Date: Thu, 25 Nov 2021 09:39:42 +0700 Subject: [PATCH 6/7] fix Sale transitions --- .../src/Ext/Plutus/Ledger/Index.hs | 3 - .../Contracts/Services/Sale/Endpoints.hs | 3 +- .../Contracts/Services/Sale/StateMachine.hs | 6 +- MetaLamp/nft-marketplace/test/Main.hs | 4 +- .../test/Marketplace/Spec/Sale.hs | 111 +++++++++--------- 5 files changed, 66 insertions(+), 61 deletions(-) diff --git a/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs index 45ca7e53c..88d6cdf0a 100644 --- a/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs +++ b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs @@ -8,6 +8,3 @@ import Plutus.V1.Ledger.Ada (Ada, lovelaceValueOf, fromValue, toValue) -- Read minUTxOValue from `testnet-shelley-genesis.json` cardano-node config minAdaTxOutValue :: Value minAdaTxOutValue = toValue minAdaTxOut - -withMinAdaTxOutValue :: Ada -> Value -withMinAdaTxOutValue initialTxOut = toValue (initialTxOut + minAdaTxOut) diff --git a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/Endpoints.hs b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/Endpoints.hs index 9d241d411..59c80d1fc 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/Endpoints.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/Endpoints.hs @@ -40,6 +40,7 @@ import Prelude (Semig import qualified Prelude as Haskell import qualified Schema import Text.Printf (printf) +import Ext.Plutus.Ledger.Index (minAdaTxOutValue) data OpenSaleParams = OpenSaleParams { @@ -66,7 +67,7 @@ openSale OpenSaleParams {..} = do saleOperatorFee = ospSaleFee } let client = Core.saleClient sale - void $ mapError (T.pack . Haskell.show @SMContractError) $ runInitialise client Core.SaleOngoing ospSaleValue + void $ mapError (T.pack . Haskell.show @SMContractError) $ runInitialise client Core.SaleOngoing (ospSaleValue + minAdaTxOutValue) logInfo @Haskell.String $ printf "Opened Sale %s at address %s" (Haskell.show sale) (Haskell.show $ Core.saleAddress sale) pure sale diff --git a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/StateMachine.hs b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/StateMachine.hs index d981a15d0..3f09d874f 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/StateMachine.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/StateMachine.hs @@ -33,6 +33,7 @@ import PlutusTx.Prelude hiding (Semigroup (..)) import Prelude (Semigroup (..), (/)) import qualified Prelude as Haskell import qualified Schema +import Ext.Plutus.Ledger.Index (minAdaTxOutValue) data SaleRedeemer = Buy Buyer @@ -74,15 +75,16 @@ transition additionalConstraints sale@Sale{..} state redeemer = case (stateData Constraints.mustPayToPubKey saleOwner val , State SaleClosed mempty ) - (SaleOngoing, Buy buyer) | saleValue == val + (SaleOngoing, Buy buyer) | saleValueWithMinAdaTxOut == val -> Just ( Constraints.mustBeSignedBy buyer <> - Constraints.mustPayToPubKey buyer saleValue <> + Constraints.mustPayToPubKey buyer saleValueWithMinAdaTxOut <> -- TODO: is it okay that buyer receive additional 2ADA? Should we initially add them to the sale price? additionalConstraints sale , State SaleClosed mempty ) _ -> Nothing where val = stateValue state + saleValueWithMinAdaTxOut = saleValue + minAdaTxOutValue {-# INLINABLE isFinal #-} isFinal :: SaleDatum -> Bool diff --git a/MetaLamp/nft-marketplace/test/Main.hs b/MetaLamp/nft-marketplace/test/Main.hs index 12bd6da7a..42c7dac2b 100644 --- a/MetaLamp/nft-marketplace/test/Main.hs +++ b/MetaLamp/nft-marketplace/test/Main.hs @@ -20,6 +20,6 @@ tests = "All tests" [ testGroup "NFT Marketplace" - [Start.tests, CreateNft.tests, Bundles.tests, Auction.tests] -- , Sale.tests] - -- , testGroup "Abstract" [RemoteData.tests, Percentage.tests] + [Start.tests, CreateNft.tests, Bundles.tests, Auction.tests, Sale.tests] + , testGroup "Abstract" [RemoteData.tests, Percentage.tests] ] diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs index a726232b4..ad412e83f 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs @@ -70,48 +70,48 @@ tests = Fixtures.options "Should not sell NFT if it has no lot" errorCheckBuyer - buyItemTrace' - -- checkPredicateOptions - -- Fixtures.options - -- "Should sell NFT and pay fee to marketplace operator" - -- (marketplaceOperatorFeeCheck .&&. sellersProfitWithPayingFeeCheck) - -- buyItemTrace + buyItemTrace', + checkPredicateOptions + Fixtures.options + "Should sell NFT and pay fee to marketplace operator" + (marketplaceOperatorFeeCheck .&&. sellersProfitWithPayingFeeCheck) + buyItemTrace + ], + testGroup + "NFT bundles" + [ + checkPredicateOptions + Fixtures.options + "Should put on sale NFT bundle locking bundle value in sale script & saving link" + (openSaleValueCheckB .&&. openSaleDatumsCheckB) + (void openSaleTraceB), + checkPredicateOptions + Fixtures.options + "Should not put on sale if bundle does not exist" + errorCheckOpen + openSaleTraceB', + checkPredicateOptions + Fixtures.options + "Should close sale and pay locked bundle value back" + (closeSaleValueCheckB .&&. completeSaleDatumsCheckB) + closeSaleTraceB, + checkPredicateOptions + Fixtures.options + "Should sell bundle and pay its value to buyer" + (buyItemValueCheckB .&&. completeSaleDatumsCheckB) + buyItemTraceB, + checkPredicateOptions + Fixtures.options + "Should sell bundle and pay fee to marketplace operator" + (marketplaceOperatorFeeCheckB .&&. sellersProfitWithPayingFeeCheckB) + buyItemTraceB ]] - -- , - -- testGroup - -- "NFT bundles" - -- [ - -- checkPredicateOptions - -- Fixtures.options - -- "Should put on sale NFT bundle locking bundle value in sale script & saving link" - -- (openSaleValueCheckB .&&. openSaleDatumsCheckB) - -- (void openSaleTraceB), - -- checkPredicateOptions - -- Fixtures.options - -- "Should not put on sale if bundle does not exist" - -- errorCheckOpen - -- openSaleTraceB', - -- checkPredicateOptions - -- Fixtures.options - -- "Should close sale and pay locked bundle value back" - -- (closeSaleValueCheckB .&&. completeSaleDatumsCheckB) - -- closeSaleTraceB, - -- checkPredicateOptions - -- Fixtures.options - -- "Should sell bundle and pay its value to buyer" - -- (buyItemValueCheckB .&&. completeSaleDatumsCheckB) - -- buyItemTraceB, - -- checkPredicateOptions - -- Fixtures.options - -- "Should sell bundle and pay fee to marketplace operator" - -- (marketplaceOperatorFeeCheckB .&&. sellersProfitWithPayingFeeCheckB) - -- buyItemTraceB - -- ]] + +-- \/\/\/ "NFT singletons" singletonNftPrice :: Integer singletonNftPrice = 60 * Fixtures.oneAdaInLovelace --- \/\/\/ "NFT singletons" openSaleParams :: Marketplace.OpenSaleParams openSaleParams = Marketplace.OpenSaleParams { Marketplace.ospItemId = Marketplace.UserNftId Fixtures.catTokenIpfsCid, @@ -232,11 +232,16 @@ errorCheckClose = Utils.assertCrError (Proxy @"closeSale") (Marketplace.userEndp errorCheckBuyer :: TracePredicate errorCheckBuyer = Utils.assertCrError (Proxy @"buyItem") (Marketplace.userEndpoints Fixtures.marketplace) (Trace.walletInstanceTag Fixtures.buyerWallet) + -- \/\/\/ "NFT bundles" + +bundleNftPrice :: Integer +bundleNftPrice = 85 * Fixtures.oneAdaInLovelace + openSaleParamsB :: Marketplace.OpenSaleParams openSaleParamsB = Marketplace.OpenSaleParams { Marketplace.ospItemId = Marketplace.UserBundleId Fixtures.cids, - Marketplace.ospSalePrice = 65 * Fixtures.oneAdaInLovelace + Marketplace.ospSalePrice = bundleNftPrice } closeLotParamsB :: Marketplace.CloseLotParams @@ -330,36 +335,36 @@ buyItemValueCheckB = marketplaceOperatorFeeCheck :: TracePredicate marketplaceOperatorFeeCheck = - walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + saleFee - minAdaTxOut) - -- 60_000_000 * 3.5 /100 = 2_100_000 - fee by complete sale - -- 2_100_000 - fee by minting token - -- 2_000_000 - minAdaTxOut by starting marketplace - -- (2_100_000 + 2_100_000 - 2_000_000) = 2_200_000 + walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + saleFee - openMarketplaceFee) where totalMintingFee = Fixtures.marketplaceCreationFee saleFee = Lovelace $ Fixtures.roundedPercentage singletonNftPrice + openMarketplaceFee = minAdaTxOut sellersProfitWithPayingFeeCheck :: TracePredicate sellersProfitWithPayingFeeCheck = - walletFundsChange Fixtures.userWallet $ toValue (nftPriceAda - saleFee - totalMintingFee) - -- 44000000 - 1200000 = 42800000 - seller's profit + walletFundsChange Fixtures.userWallet $ toValue (nftPriceAda - saleFee - totalMintingFee - openSaleFee) where - saleFee = Lovelace $ Fixtures.roundedPercentage singletonNftPrice totalMintingFee = Fixtures.marketplaceCreationFee nftPriceAda = Lovelace singletonNftPrice + saleFee = Lovelace $ Fixtures.roundedPercentage singletonNftPrice + openSaleFee = minAdaTxOut marketplaceOperatorFeeCheckB :: TracePredicate marketplaceOperatorFeeCheckB = - walletFundsChange Fixtures.ownerWallet $ lovelaceValueOf 1925000 - -- 65_000_000 * 3.5 /100 = 1_625_000 - fee by complete sale - -- 100_000 * 2 = 200000 - fee by minting 2 tokens - -- 100_000 - fee by bundling + walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + totalBundlingFee + saleFee - openMarketplaceFee) where totalMintingFee = Fixtures.marketplaceCreationFee * 2 totalBundlingFee = Fixtures.marketplaceCreationFee - + saleFee = Lovelace $ Fixtures.roundedPercentage bundleNftPrice + openMarketplaceFee = minAdaTxOut sellersProfitWithPayingFeeCheckB :: TracePredicate sellersProfitWithPayingFeeCheckB = - walletFundsChange Fixtures.userWallet $ lovelaceValueOf 63075000 - -- 65000000 - 1925000 = 63075000 + walletFundsChange Fixtures.userWallet $ toValue (bundlePriceAda - totalMintingFee - totalBundlingFee - openSaleFee - saleFee) + where + totalMintingFee = Fixtures.marketplaceCreationFee * 2 + totalBundlingFee = Fixtures.marketplaceCreationFee + saleFee = Lovelace $ Fixtures.roundedPercentage bundleNftPrice + bundlePriceAda = Lovelace bundleNftPrice + openSaleFee = minAdaTxOut From caab8f726d5986d3204724e2cfc3559190e7f2e8 Mon Sep 17 00:00:00 2001 From: olgaklimenko Date: Thu, 25 Nov 2021 09:59:50 +0700 Subject: [PATCH 7/7] add explicit minAdaTxOut to transactions --- .../src/Ext/Plutus/Ledger/Index.hs | 5 +++-- .../NftMarketplace/OffChain/Owner.hs | 4 ++-- .../Contracts/Services/Auction/Endpoints.hs | 3 ++- .../Services/Auction/StateMachine.hs | 6 ++++-- .../Contracts/Services/Sale/Endpoints.hs | 2 +- .../Contracts/Services/Sale/StateMachine.hs | 7 ++++--- .../test/Marketplace/Fixtures/Script.hs | 6 +++--- .../test/Marketplace/Spec/Auction.hs | 16 +++++++------- .../test/Marketplace/Spec/Bundles.hs | 4 ++-- .../test/Marketplace/Spec/CreateNft.hs | 2 +- .../test/Marketplace/Spec/Sale.hs | 21 +++++++------------ .../test/Marketplace/Spec/Start.hs | 11 +++++----- 12 files changed, 43 insertions(+), 44 deletions(-) diff --git a/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs index 88d6cdf0a..114834f90 100644 --- a/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs +++ b/MetaLamp/nft-marketplace/src/Ext/Plutus/Ledger/Index.hs @@ -1,8 +1,9 @@ module Ext.Plutus.Ledger.Index where -import Ledger.Index (minAdaTxOut) +import Ledger.Index (minAdaTxOut) +import Plutus.V1.Ledger.Ada (Ada, fromValue, lovelaceValueOf, + toValue) import Plutus.V1.Ledger.Value (Value) -import Plutus.V1.Ledger.Ada (Ada, lovelaceValueOf, fromValue, toValue) -- TODO: That should be configurable in future: -- Read minUTxOValue from `testnet-shelley-genesis.json` cardano-node config diff --git a/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs b/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs index 1c59a1066..07f61bd72 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Contracts/NftMarketplace/OffChain/Owner.hs @@ -16,6 +16,7 @@ import qualified Data.Aeson as J import Data.Proxy (Proxy (..)) import Data.Text (Text) import qualified Data.Text as T +import Ext.Plutus.Ledger.Index (minAdaTxOutValue) import qualified GHC.Generics as Haskell import Ledger import Ledger.Ada (Ada (..)) @@ -31,6 +32,7 @@ import Plutus.Contract.Request (ownPubKeyHash) import Plutus.Contract.StateMachine import Plutus.Contracts.Currency as Currency import qualified Plutus.Contracts.NftMarketplace.OnChain.Core as Core +import Plutus.V1.Ledger.Ada (lovelaceValueOf) import qualified PlutusTx import qualified PlutusTx.AssocMap as AssocMap import PlutusTx.Prelude hiding @@ -39,8 +41,6 @@ import Prelude (Semigroup (..)) import qualified Prelude as Haskell import qualified Schema import Text.Printf (printf) -import Plutus.V1.Ledger.Ada (lovelaceValueOf) -import Ext.Plutus.Ledger.Index (minAdaTxOutValue) data StartMarketplaceParams = StartMarketplaceParams { creationFee :: Integer, -- fee by minting and bundling diff --git a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Auction/Endpoints.hs b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Auction/Endpoints.hs index 009aacd90..1efa34a09 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Auction/Endpoints.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Auction/Endpoints.hs @@ -23,6 +23,7 @@ import qualified Data.Aeson as J import Data.Monoid (Last (..)) import Data.Semigroup.Generic (GenericSemigroupMonoid (..)) import qualified Data.Text as T +import Ext.Plutus.Ledger.Index (minAdaTxOutValue) import GHC.Generics (Generic) import Ledger (Ada, PubKeyHash, @@ -83,7 +84,7 @@ startAuction StartAuctionParams{..} = do _ <- handleError (\e -> do { logError (AuctionFailed e); throwError (StateMachineContractError e) }) - (SM.runInitialise client (initialState aOwner) aAsset) + (SM.runInitialise client (initialState aOwner) (aAsset + minAdaTxOutValue)) logInfo $ AuctionStarted auction pure auction diff --git a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Auction/StateMachine.hs b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Auction/StateMachine.hs index 8ab5bf1b7..e66c83562 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Auction/StateMachine.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Auction/StateMachine.hs @@ -19,6 +19,7 @@ import Data.Aeson (FromJSON, ToJSON) import qualified Data.Aeson as J import Data.Monoid (Last (..)) import Data.Semigroup.Generic (GenericSemigroupMonoid (..)) +import Ext.Plutus.Ledger.Index (minAdaTxOutValue) import GHC.Generics (Generic) import Ledger (Ada, PubKeyHash, Slot, Value) @@ -140,7 +141,7 @@ auctionTransition getAdditionalPayoutConstraints params@Auction{..} state@State{ let additionalConstraints = getAdditionalPayoutConstraints params state constraints = - Constraints.mustPayToPubKey highestBidder aAsset -- and the highest bidder the asset + Constraints.mustPayToPubKey highestBidder (aAsset + minAdaTxOutValue) -- and the highest bidder the asset <> additionalConstraints <> Constraints.mustValidateIn (Interval.from aEndTime) -- When the auction has ended, newState = State { stateData = Finished h, stateValue = mempty } @@ -151,7 +152,8 @@ auctionTransition getAdditionalPayoutConstraints params@Auction{..} state@State{ constraints = Constraints.mustValidateIn (Interval.to aEndTime) -- While the auction hasn't ended, <> Constraints.mustPayToPubKey highestBidder (Ada.toValue highestBid) -- and the highest bidder the asset - <> Constraints.mustPayToPubKey aOwner aAsset -- and the highest bidder the asset + <> Constraints.mustPayToPubKey aOwner (aAsset + minAdaTxOutValue) -- and the highest bidder the asset + -- TODO: is it okay that buyer receive additional 2ADA? Should we initially add them to the bid price? newState = State { stateData = Canceled, stateValue = mempty } in Just (constraints, newState) diff --git a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/Endpoints.hs b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/Endpoints.hs index 59c80d1fc..e3e4c21c1 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/Endpoints.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/Endpoints.hs @@ -31,6 +31,7 @@ import qualified Plutus.Contracts.NftMarketplace.OnChain.Core.Marketplace as Mar import qualified Plutus.Contracts.Services.Sale.Core as Core import qualified Plutus.Contracts.Services.Sale.StateMachine as Core +import Ext.Plutus.Ledger.Index (minAdaTxOutValue) import Plutus.Contract.Request (ownPubKeyHash) import qualified PlutusTx import qualified PlutusTx.AssocMap as AssocMap @@ -40,7 +41,6 @@ import Prelude (Semig import qualified Prelude as Haskell import qualified Schema import Text.Printf (printf) -import Ext.Plutus.Ledger.Index (minAdaTxOutValue) data OpenSaleParams = OpenSaleParams { diff --git a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/StateMachine.hs b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/StateMachine.hs index 3f09d874f..04fea950a 100644 --- a/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/StateMachine.hs +++ b/MetaLamp/nft-marketplace/src/Plutus/Contracts/Services/Sale/StateMachine.hs @@ -15,6 +15,7 @@ module Plutus.Contracts.Services.Sale.StateMachine where import qualified Control.Lens as Lens import qualified Data.Aeson as J import qualified Data.Text as T +import Ext.Plutus.Ledger.Index (minAdaTxOutValue) import qualified GHC.Generics as Haskell import Ledger import qualified Ledger.Ada as Ada @@ -33,7 +34,6 @@ import PlutusTx.Prelude hiding (Semigroup (..)) import Prelude (Semigroup (..), (/)) import qualified Prelude as Haskell import qualified Schema -import Ext.Plutus.Ledger.Index (minAdaTxOutValue) data SaleRedeemer = Buy Buyer @@ -72,12 +72,13 @@ transition :: GetAdditionalConstraints -> Sale -> State SaleDatum -> SaleRedeeme transition additionalConstraints sale@Sale{..} state redeemer = case (stateData state, redeemer) of (SaleOngoing, Redeem) -> Just ( Constraints.mustBeSignedBy saleOwner <> - Constraints.mustPayToPubKey saleOwner val + Constraints.mustPayToPubKey saleOwner saleValueWithMinAdaTxOut , State SaleClosed mempty ) (SaleOngoing, Buy buyer) | saleValueWithMinAdaTxOut == val -> Just ( Constraints.mustBeSignedBy buyer <> - Constraints.mustPayToPubKey buyer saleValueWithMinAdaTxOut <> -- TODO: is it okay that buyer receive additional 2ADA? Should we initially add them to the sale price? + Constraints.mustPayToPubKey buyer saleValueWithMinAdaTxOut <> + -- TODO: is it okay that buyer receive additional 2ADA? Should we initially add them to the sale price? additionalConstraints sale , State SaleClosed mempty ) diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Fixtures/Script.hs b/MetaLamp/nft-marketplace/test/Marketplace/Fixtures/Script.hs index a39f5e668..3123792d5 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Fixtures/Script.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Fixtures/Script.hs @@ -1,6 +1,6 @@ -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE OverloadedStrings #-} module Marketplace.Fixtures.Script where import Ledger (Address, @@ -10,10 +10,10 @@ import Ledger.Ada (Ada (..)) import qualified Ledger.Value as V import qualified Marketplace.Fixtures.Wallet as Fixtures import Plutus.Abstract.Percentage (Percentage (..)) +import Plutus.Abstract.PercentageInterface (calculatePercentageRounded) import qualified Plutus.Contracts.NftMarketplace.OnChain.Core as Marketplace import Wallet.Emulator.Types (Wallet (..), walletPubKeyHash) -import Plutus.Abstract.PercentageInterface (calculatePercentageRounded) marketplace :: Marketplace.Marketplace marketplace = diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Auction.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Auction.hs index 34812328d..1b46fd35d 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Auction.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Auction.hs @@ -18,6 +18,10 @@ import Data.Void (Void) import Ext.Plutus.Ledger.Time (Seconds (..), addToBeginningOfTime) import Ledger (Value) +import Ledger.Ada (Ada (..), + lovelaceValueOf, + toValue) +import Ledger.Index (minAdaTxOut) import qualified Ledger.Value as V import qualified Marketplace.Fixtures as Fixtures import qualified Marketplace.Spec.Bundles as Bundles @@ -36,8 +40,6 @@ import qualified PlutusTx.AssocMap as AssocMap import Test.Tasty import qualified Utils import Wallet.Emulator.Wallet (walletAddress) -import Ledger.Ada (Ada(..), toValue, lovelaceValueOf) -import Ledger.Index (minAdaTxOut) tests :: TestTree @@ -505,19 +507,16 @@ buyOnAuctionValueCheckB = marketplaceOperatorFeeCheck :: TracePredicate marketplaceOperatorFeeCheck = - walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + auctionFee - minAdaTxOut) + walletFundsChange Fixtures.ownerWallet $ toValue (Fixtures.marketplaceCreationFee + auctionFee - minAdaTxOut) where - totalMintingFee = Fixtures.marketplaceCreationFee auctionFee = Lovelace $ Fixtures.roundedPercentage highestBid sellerProfitWithFeeCheck :: TracePredicate sellerProfitWithFeeCheck = - walletFundsChange Fixtures.userWallet $ toValue (highestBidAda - totalMintingFee - openAuctionMinAdaTxOut - auctionFee) + walletFundsChange Fixtures.userWallet $ toValue (highestBidAda - Fixtures.marketplaceCreationFee - minAdaTxOut - auctionFee) where - totalMintingFee = Fixtures.marketplaceCreationFee auctionFee = Lovelace $ Fixtures.roundedPercentage highestBid highestBidAda = Lovelace highestBid - openAuctionMinAdaTxOut = minAdaTxOut marketplaceOperatorFeeCheckB :: TracePredicate marketplaceOperatorFeeCheckB = @@ -529,10 +528,9 @@ marketplaceOperatorFeeCheckB = sellerProfitWithFeeCheckB :: TracePredicate sellerProfitWithFeeCheckB = - walletFundsChange Fixtures.userWallet $ toValue (highestBidAda - totalMintingFee - totalBundlingFee - openAuctionMinAdaTxOut - auctionFee) + walletFundsChange Fixtures.userWallet $ toValue (highestBidAda - totalMintingFee - totalBundlingFee - minAdaTxOut - auctionFee) where totalMintingFee = Fixtures.marketplaceCreationFee * 2 totalBundlingFee = Fixtures.marketplaceCreationFee auctionFee = Lovelace $ Fixtures.roundedPercentage highestBidB highestBidAda = Lovelace highestBidB - openAuctionMinAdaTxOut = minAdaTxOut diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Bundles.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Bundles.hs index 87a1d9fad..1c51a4b56 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Bundles.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Bundles.hs @@ -14,6 +14,7 @@ import Data.Proxy import Data.Text (Text) import Data.Void (Void) import Ledger.Ada (toValue) +import Ledger.Index (minAdaTxOut) import qualified Marketplace.Fixtures as Fixtures import qualified Marketplace.Spec.Start as Start import Plutus.Abstract.ContractResponse (ContractResponse) @@ -24,7 +25,6 @@ import qualified Plutus.Trace as Trace import qualified PlutusTx.AssocMap as AssocMap import Test.Tasty import qualified Utils -import Ledger.Index (minAdaTxOut) tests :: TestTree tests = @@ -156,4 +156,4 @@ marketplaceOperatorFundsCheck = walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + totalBundlingFee - minAdaTxOut) where totalBundlingFee = Fixtures.marketplaceCreationFee - totalMintingFee = Fixtures.marketplaceCreationFee * 2 \ No newline at end of file + totalMintingFee = Fixtures.marketplaceCreationFee * 2 diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/CreateNft.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/CreateNft.hs index 90b99a46f..ae3ba278e 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/CreateNft.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/CreateNft.hs @@ -14,6 +14,7 @@ import Data.Maybe (isNothing) import Data.Text (Text) import Data.Void (Void) import Ledger.Ada (toValue) +import Ledger.Index (minAdaTxOut) import qualified Ledger.Value as V import qualified Marketplace.Fixtures as Fixtures import qualified Marketplace.Spec.Start as Start @@ -27,7 +28,6 @@ import Test.Tasty import qualified Utils import Wallet.Emulator.Wallet (walletAddress, walletPubKeyHash) -import Ledger.Index (minAdaTxOut) tests :: TestTree tests = diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs index ad412e83f..7fea2705d 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Sale.hs @@ -15,7 +15,10 @@ import Data.Maybe (isNothing) import Data.Proxy import Data.Text (Text) import Data.Void (Void) -import Ledger.Ada (lovelaceValueOf) +import Ledger.Ada (Ada (..), + lovelaceValueOf, + toValue) +import Ledger.Index (minAdaTxOut) import qualified Ledger.Value as V import qualified Marketplace.Fixtures as Fixtures import qualified Marketplace.Spec.Bundles as Bundles @@ -31,8 +34,6 @@ import qualified PlutusTx.AssocMap as AssocMap import Test.Tasty import qualified Utils import Wallet.Emulator.Wallet (walletAddress) -import Ledger.Ada (Ada(..), toValue) -import Ledger.Index (minAdaTxOut) tests :: TestTree tests = @@ -335,36 +336,30 @@ buyItemValueCheckB = marketplaceOperatorFeeCheck :: TracePredicate marketplaceOperatorFeeCheck = - walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + saleFee - openMarketplaceFee) + walletFundsChange Fixtures.ownerWallet $ toValue (Fixtures.marketplaceCreationFee + saleFee - minAdaTxOut) where - totalMintingFee = Fixtures.marketplaceCreationFee saleFee = Lovelace $ Fixtures.roundedPercentage singletonNftPrice - openMarketplaceFee = minAdaTxOut sellersProfitWithPayingFeeCheck :: TracePredicate sellersProfitWithPayingFeeCheck = - walletFundsChange Fixtures.userWallet $ toValue (nftPriceAda - saleFee - totalMintingFee - openSaleFee) + walletFundsChange Fixtures.userWallet $ toValue (nftPriceAda - saleFee - Fixtures.marketplaceCreationFee - minAdaTxOut) where - totalMintingFee = Fixtures.marketplaceCreationFee nftPriceAda = Lovelace singletonNftPrice saleFee = Lovelace $ Fixtures.roundedPercentage singletonNftPrice - openSaleFee = minAdaTxOut marketplaceOperatorFeeCheckB :: TracePredicate marketplaceOperatorFeeCheckB = - walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + totalBundlingFee + saleFee - openMarketplaceFee) + walletFundsChange Fixtures.ownerWallet $ toValue (totalMintingFee + totalBundlingFee + saleFee - minAdaTxOut) where totalMintingFee = Fixtures.marketplaceCreationFee * 2 totalBundlingFee = Fixtures.marketplaceCreationFee saleFee = Lovelace $ Fixtures.roundedPercentage bundleNftPrice - openMarketplaceFee = minAdaTxOut sellersProfitWithPayingFeeCheckB :: TracePredicate sellersProfitWithPayingFeeCheckB = - walletFundsChange Fixtures.userWallet $ toValue (bundlePriceAda - totalMintingFee - totalBundlingFee - openSaleFee - saleFee) + walletFundsChange Fixtures.userWallet $ toValue (bundlePriceAda - totalMintingFee - totalBundlingFee - minAdaTxOut - saleFee) where totalMintingFee = Fixtures.marketplaceCreationFee * 2 totalBundlingFee = Fixtures.marketplaceCreationFee saleFee = Lovelace $ Fixtures.roundedPercentage bundleNftPrice bundlePriceAda = Lovelace bundleNftPrice - openSaleFee = minAdaTxOut diff --git a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Start.hs b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Start.hs index 433184261..759fc016e 100644 --- a/MetaLamp/nft-marketplace/test/Marketplace/Spec/Start.hs +++ b/MetaLamp/nft-marketplace/test/Marketplace/Spec/Start.hs @@ -1,6 +1,6 @@ -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE OverloadedStrings #-} module Marketplace.Spec.Start ( tests, startTrace @@ -8,6 +8,9 @@ module Marketplace.Spec.Start import Control.Monad (void) import Data.Text (Text) +import Ledger.Ada (Ada (..), + toValue) +import Ledger.Index (minAdaTxOut) import qualified Ledger.Value as V import qualified Marketplace.Fixtures as Fixtures import Plutus.Abstract.Percentage (getPercentage) @@ -19,8 +22,6 @@ import qualified Plutus.Contracts.NftMarketplace.OnChain.Core as Marketplace import qualified Plutus.Trace as Trace import qualified PlutusTx.AssocMap as AssocMap import Test.Tasty -import Ledger.Ada (toValue, Ada(..)) -import Ledger.Index (minAdaTxOut) tests :: TestTree tests = @@ -56,7 +57,7 @@ datumsCheck = (== [Marketplace.MarketplaceDatum AssocMap.empty AssocMap.empty]) marketplaceOpenedWithMinAdaTxOut :: TracePredicate -marketplaceOpenedWithMinAdaTxOut = +marketplaceOpenedWithMinAdaTxOut = valueAtAddress Fixtures.marketplaceAddress (toValue minAdaTxOut ==) marketplaceOperatorPayedMinAdaTxOut :: TracePredicate