atlas icon indicating copy to clipboard operation
atlas copied to clipboard

Unknown source of extra Lovelace after unit test run

Open Fiftyw3bs opened this issue 1 year ago • 3 comments

Describe the bug

My test uses withWalletBalancesCheckSimple to validate the wallet balance after submitting transaction:

withWalletBalancesCheckSimple [w1 := valueSingleton
      ( case
            cAssetClass
          of
            Left _ -> GYLovelace
            Right x -> x
      ) 1 <> valueNegate (valueSingleton fakeGold 100) ] $ do mintOwnerTokenRun cSettings c

But I get the following result with an extra 1667970 lovelace

[error] Generic fail: Wallet: w1. 

Old balance: 1000000 02384095adfb494c4d3b53fad4fc44ce2da4db629c50cf627901b804.476f6c64 + 1000000 01f0ef87e344b733286dfce55cfd7e10c90b57a3b1825c984454ce6a.49726f6e + 1000000000000 lovelace. 

New balance: 1 569c5e8498ee05e8651ad68b6c81f9756852e218933db722ebc72b90.436f6c6f6e794f776e6572 + 999900 02384095adfb494c4d3b53fad4fc44ce2da4db629c50cf627901b804.476f6c64 + 1000000 01f0ef87e344b733286dfce55cfd7e10c90b57a3b1825c984454ce6a.49726f6e + 999998544685 lovelace. 

New balance after adding extra lovelaces 1 569c5e8498ee05e8651ad68b6c81f9756852e218933db722ebc72b90.436f6c6f6e794f776e6572 + 999900 02384095adfb494c4d3b53fad4fc44ce2da4db629c50cf627901b804.476f6c64 + 1000000 01f0ef87e344b733286dfce55cfd7e10c90b57a3b1825c984454ce6a.49726f6e + 1000001667970 lovelace. 

Expected balance difference of 1 569c5e8498ee05e8651ad68b6c81f9756852e218933db722ebc72b90.436f6c6f6e794f776e6572 + -100 02384095adfb494c4d3b53fad4fc44ce2da4db629c50cf627901b804.476f6c64, but the actual difference was 1 569c5e8498ee05e8651ad68b6c81f9756852e218933db722ebc72b90.436f6c6f6e794f776e6572 + -100 02384095adfb494c4d3b53fad4fc44ce2da4db629c50cf627901b804.476f6c64 + 1667970 lovelace

Expected behavior Successful check of wallet balance.

Station (please complete the following information):

  • OS: Nix
  • Version 2.19.2

Fiftyw3bs avatar Jan 21 '24 08:01 Fiftyw3bs

So your wallet was suppose to lose 100 of 02384095adfb494c4d3b53fad4fc44ce2da4db629c50cf627901b804.476f6c64 and gain one of 569c5e8498ee05e8651ad68b6c81f9756852e218933db722ebc72b90.436f6c6f6e794f776e6572, are you sure that in the operation you are doing, wallet is not suppose to receive any ada?

sourabhxyz avatar Jan 22 '24 05:01 sourabhxyz

Below is an excerpt of the off-chain code:

return $ fromJust (mustMint (GYMintScript $ colonyMintingPolicy' cSettings stepAddress treasuryAddress colony) redeemer
                             <$> tokenNameFromPlutus (fromMemberTypeToTokenName ColonyOwner)
                             <*> Just (toInteger (length creators)))
           <>
           foldMap mustBeSignedBy creators
           <>
           foldMap mustHaveOutput (GYTxOut <$> (addressFromPubKeyHash GYTestnetPreprod <$> creators)
                                          <*> [fromRight (valueFromLovelace 0) $ valueFromPlutus colonyOwnerToken]
                                          <*> [Just (colonyDatum, GYTxOutUseInlineDatum)]
                                          <*> [Nothing])
           <>
           mustHaveOutput (mkGYTxOut feeAddress (colonyCreationFee' cSettings) colonyDatum)

colonyCreationFee' is the 100 fakeGold (02384095adfb494c4d3b53fad4fc44ce2da4db629c50cf627901b804.476f6c64) colonyOwnerToken is 569c5e8498ee05e8651ad68b6c81f9756852e218933db722ebc72b90.436f6c6f6e794f776e6572

Could it be that change is being returned to the creator's wallet?

BTW, how do I activate traces? I've stopped seeing them since I bumped atlas to v0.4.0

Fiftyw3bs avatar Jan 22 '24 12:01 Fiftyw3bs

@Fiftyw3bs Since Atlas unit testing mechanism is revamped, are you still facing this issue?

sourabhxyz avatar Sep 17 '24 10:09 sourabhxyz

@sourabhxyz The issue is resolved. It is actually not even an issue. I was just too preoccupied with other things and distracted to realize, that it's just the minimum ada value of 1667970 lovelace required for sending the token to the script address, which is also being deducted from the user wallet.

Thanks ;)

Fiftyw3bs avatar Oct 11 '24 14:10 Fiftyw3bs