Skip to content

Commit

Permalink
Account for fees during AutoExecution
Browse files Browse the repository at this point in the history
  • Loading branch information
nau committed Apr 6, 2021
1 parent 31fa230 commit 6caee7c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions marlowe/test/Spec/Marlowe/AutoExecute.hs
Expand Up @@ -75,8 +75,8 @@ autoexecZCBTest = checkPredicate "ZCB Auto Execute Contract"
-- /\ emulatorLog (const False) ""
T..&&. assertNotDone (marlowePlutusContract) (Trace.walletInstanceTag alice) "contract should not have any errors"
T..&&. assertNotDone (marlowePlutusContract) (Trace.walletInstanceTag bob) "contract should not have any errors"
T..&&. walletFundsChange alice (lovelaceValueOf (150))
T..&&. walletFundsChange bob (lovelaceValueOf (-150))
T..&&. walletFundsChange alice (lovelaceValueOf (120))
T..&&. walletFundsChange bob (lovelaceValueOf (-160))
) $ do

bobHdl <- Trace.activateContractWallet bob marlowePlutusContract
Expand All @@ -90,14 +90,15 @@ autoexecZCBTest = checkPredicate "ZCB Auto Execute Contract"
Trace.waitNSlots 1

-- Move all Alice's money to Carol, so she can't make a payment
Trace.payToWallet alice carol defaultLovelaceAmount
-- Leave some lovelace for fees
Trace.payToWallet alice carol (defaultLovelaceAmount <> P.inv (lovelaceValueOf 50))
Trace.waitNSlots 1

Trace.callEndpoint @"auto" aliceHdl (params, alicePk, contractLifespan)
Trace.waitNSlots 1

-- Return money to Alice
Trace.payToWallet carol alice defaultLovelaceAmount
Trace.payToWallet carol alice (defaultLovelaceAmount <> P.inv (lovelaceValueOf 50))
Trace.waitNSlots 1

-- Now Alice should be able to retry and pay to Bob
Expand All @@ -111,8 +112,8 @@ autoexecZCBTestAliceWalksAway = checkPredicate
-- /\ emulatorLog (const False) ""
T..&&. assertNotDone (marlowePlutusContract) (Trace.walletInstanceTag alice) "contract should not have any errors"
T..&&. assertNotDone (marlowePlutusContract) (Trace.walletInstanceTag bob) "contract should not have any errors"
T..&&. walletFundsChange alice (P.inv defaultLovelaceAmount)
T..&&. walletFundsChange carol defaultLovelaceAmount
T..&&. walletFundsChange alice (P.inv (defaultLovelaceAmount <> P.inv (lovelaceValueOf 30)))
T..&&. walletFundsChange carol (defaultLovelaceAmount <> P.inv (lovelaceValueOf 50))
) $ do
bobHdl <- Trace.activateContractWallet bob marlowePlutusContract
aliceHdl <- Trace.activateContractWallet alice marlowePlutusContract
Expand All @@ -125,7 +126,7 @@ autoexecZCBTestAliceWalksAway = checkPredicate
Trace.waitNSlots 1

-- Move all Alice's money to Carol, so she can't make a payment
Trace.payToWallet alice carol defaultLovelaceAmount
Trace.payToWallet alice carol (defaultLovelaceAmount <> P.inv (lovelaceValueOf 50))
Trace.waitNSlots 1

Trace.callEndpoint @"auto" aliceHdl (params, alicePk, contractLifespan)
Expand All @@ -142,8 +143,8 @@ autoexecZCBTestBobWalksAway = checkPredicate
-- /\ emulatorLog (const False) ""
T..&&. assertNotDone (marlowePlutusContract) (Trace.walletInstanceTag alice) "contract should not have any errors"
T..&&. assertNotDone (marlowePlutusContract) (Trace.walletInstanceTag bob) "contract should not have any errors"
T..&&. walletFundsChange alice (lovelaceValueOf (-850))
T..&&. walletFundsChange carol defaultLovelaceAmount
T..&&. walletFundsChange alice (lovelaceValueOf (-870))
T..&&. walletFundsChange carol (defaultLovelaceAmount <> P.inv (lovelaceValueOf 50))
) $ do
bobHdl <- Trace.activateContractWallet bob marlowePlutusContract
aliceHdl <- Trace.activateContractWallet alice marlowePlutusContract
Expand All @@ -155,7 +156,7 @@ autoexecZCBTestBobWalksAway = checkPredicate
Trace.callEndpoint @"create" aliceHdl (AssocMap.empty, zeroCouponBond)
Trace.waitNSlots 1

Trace.payToWallet bob carol defaultLovelaceAmount
Trace.payToWallet bob carol (defaultLovelaceAmount <> P.inv (lovelaceValueOf 50))
Trace.waitNSlots 1

Trace.callEndpoint @"auto" aliceHdl (params, alicePk, contractLifespan)
Expand Down Expand Up @@ -199,3 +200,6 @@ contractLifespan = contractLifespanUpperBound zeroCouponBond

defaultLovelaceAmount :: Ledger.Value
defaultLovelaceAmount = defaultDist Map.! alice

staticFee :: Ledger.Value
staticFee = Ledger.minFee mempty

0 comments on commit 6caee7c

Please sign in to comment.