mlabs-haskell / seabug-contracts

3 stars 1 forks source link

Tests #41

Closed rynoV closed 2 years ago

rynoV commented 2 years ago

Closes #32

Minting testing # Minting testing We test: - The cnft goes to the minter's address at first - The sgnft goes to the marketplace script's address - The cnft goes to the locking script when the sgnft is minted - The cnft utxo has the correct locking datum - The sgnft utxo has the correct marketplace datum - The sgnft mint tx has the correct metadata We also test failing transactions: - Cnft mint does not spend correct utxo - Sgnft mints more than one - Sgnft mint does not send cnft to locking script
Buy testing # Buy Testing For each of the below test cases, we check: - updated sgNft goes back to marketplace or the buyer, as determined by `retBehaviour` - marketplace does not hold the old sgNft - marketplace, author, and owner each get their expected shares - "low share" test cases mean the shares are too low to meet the min ada requirement - marketplace is an exception, we check that it gains its full share minus `mpExpectedLoss` - buyer lost at least `buyerExpectedLoss` - Everyone got the expected payment utxos with the expected datum - The tx metadata is correct **Test cases**: ``` ~ price too low for min ada requirement ~ fractional shares (.5) ~ fractional shares (.5), author is not seller ~ fractional shares (.1) ~ fractional shares (.1), author is not seller ~ fractional shares (.9) ~ fractional shares (.9), author is not seller ~ no low shares ~ no low shares, nft to buyer ~ no low shares, author is not seller ~ no low shares, author is not seller, nft to buyer ~ low marketplace share ~ low marketplace share, nft to buyer ~ low marketplace share, author is not seller ~ low marketplace share, author is not seller, nft to buyer ~ low author share ~ low author share, nft to buyer ~ low author share, author is not seller ~ low author share, author is not seller, nft to buyer ~ low author and marketplace shares ~ low author and marketplace shares, nft to buyer ~ low author and marketplace shares, author is not seller ~ low author and marketplace shares, author is not seller, nft to buyer ``` ## Buyer not paying full price `buyerExpectedLoss` and `mpExpectedLoss` are defined as follows: ``` mpInit := Ada in the utxo holding the nft locked by the marketplace script txFee := Buy transaction fee, in ada price := Marketplace price of the nft mpRemainder := mpInit - txFee buyerExpectedLoss := price - mpRemainder mpExpectedLoss := mpInit ``` For example, given the transaction [910f14c0d53e7466f5ba7ac2e3d20a51f30344ba74808aa8ebeadf143ee7a885](https://explorer.cardano-testnet.iohkdev.io/en/transaction?id=910f14c0d53e7466f5ba7ac2e3d20a51f30344ba74808aa8ebeadf143ee7a885): ![2022-08-24-114638_651x453_scrot](https://user-images.githubusercontent.com/35615725/186487965-7e0d53a9-2044-4d3b-80d4-6f5a93197f3c.png) ``` buyerInit := 143.487861 mpInit := 1.28869 buyerOut := 130.673502 buyerExtra := 1.41368 txFee := 0.689369 buyerTotalOut := buyerOut + buyerExtra => 132.087182 buyerPaid := buyerInit - buyerTotalOut => 11.400679 price := 12 buyerAvoided := price - buyerPaid => 0.599321 mpRemainder := mpInit - txFee => 0.599321 buyerRemainder := buyerInit - buyerOut - price => 0.814359 buyerRemainder + mpRemainder => 1.41368 buyerExpectedLoss := price - mpRemainder => 11.400679 mpExpectedLoss := mpInit => 1.28869 ``` To summarize, when the sgNft is sent to the buyer, the marketplace script ends up covering tx fees, and the remainder from the marketplace utxo goes towards funding the min ada required for the buyer's nft utxo, which leads to the buyer paying less than the full price after accounting for the nft utxo
samuelWilliams99 commented 2 years ago

Can we get the other checks fixed? Theres some warnings about imports

rynoV commented 2 years ago

Can we get the other checks fixed? Theres some warnings about imports

Right now I think we have to wait for https://github.com/Plutonomicon/cardano-transaction-lib/pull/906, it's making some fairly big changes that we'll need, after that I'll go through and make sure all the checks are passing

Theres a lot of code here that should definitely be generalised, have you spoke to the CTL guys about getting this added somewhere?

Just made an issue: https://github.com/Plutonomicon/cardano-transaction-lib/issues/948

rynoV commented 2 years ago

@samuelWilliams99 This should be ready for merge now. One thing though is that the plutip tests take ~15 minutes to run: https://ci.staging.mlabs.city/build/261068. For local development this isn't a big issue since you can run only some tests and skip others, but it's probably not great for CI.

I don't think there's much we can do about it right now, but if it's an issue I can make an issue and bring it up to the CTL team

samuelWilliams99 commented 2 years ago

Looks good to me :D