geniusyield / atlas

Application backend for Plutus smart contracts on Cardano
https://atlas-app.io
Apache License 2.0
67 stars 18 forks source link

Make feetracker track unexpected gains from inputs #344

Closed TotallyNotChase closed 2 months ago

TotallyNotChase commented 2 months ago

This lets the feetracker track gains from min ada deposits consumed from inputs.

Previously, tests like these would fail:

let amt = valueSingleton valueSingleton testGoldAsset 10
withWalletBalancesCheckSimple [w1 := valueNegate amt, w2 := amt] $ do
    target <- scriptAddress gyAlwaysSucceedsValidator
    txId <- asUser w1 $ do
        txBody <- buildTxBody . mustHaveOutput $ mkGYTxOut target amt unitDatum
        signAndSubmitConfirmed txBody
    asUser w2 $ do
        txBody <- buildTxBody @PlutusV1 . mustHaveInput $ GYTxIn
            { gyTxInWitness  = GYTxInWitnessScript (GYInScript gyAlwaysSucceedsValidator) unitDatum unitRedeemer
            , gyTxInTxOutRef = txOutRefFromTuple (txId, 0)
            }
        signAndSubmitConfirmed_ txBody

Here, w1 loses some lovelace to paying a deposit to the UTxO created in the first transaction. This is, of course, tracked by fee tracker - so it's all good. However, in the next transaction, w2 actually gains this deposit. But this is not tracked at all! So there is an unexpected gain.

This PR also adds a bunch of tests for feetracker.

sourabhxyz commented 2 months ago

@TotallyNotChase thanks for this contribution! I have reviewed the PR, could you let me know your thoughts on this comment?