Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet's utxos in Emulator's diskstate have incorrect indexes #695

Closed
catch-21 opened this issue Sep 5, 2022 · 1 comment · Fixed by #766
Closed

Wallet's utxos in Emulator's diskstate have incorrect indexes #695

catch-21 opened this issue Sep 5, 2022 · 1 comment · Fixed by #766
Labels
bug Something isn't working Tracked Issue is tracked in our internal backlog

Comments

@catch-21
Copy link
Contributor

catch-21 commented Sep 5, 2022

Summary

Accessing the wallet's utxos from the WalletState of the EmulatorTrace results in TxOutRefs with indexes in the range 0-9 for all wallets, this cannot be correct because each wallet must have unique utxos. The Contract sees unique TxOutRefs for each wallet, e.g. w1 uses index range 50-59 and w2 uses 20-29.

Steps to reproduce the behavior

There are currently workarounds for this bug in existing tests mustSpendPubKeyOutput plutus-context tests, such as this. Please remove workarounds once fixed.

There is a commented out test to recreate this bug, see here. Edit: this also now affects MustReferenceOutput tests

Actual Result

Getting TxOutRef from WalletState, w1TxoRefs will have indexes in range 0-9.

let trace :: Trace.EmulatorTrace () = do
        w1State <- Trace.agentState w1
        let w1TxoRefs = S.elems $ head $ M.elems $ w1State ^. chainIndexEmulatorState . diskState . addressMap . unCredentialMap

Logging in Contract will print indexes in range 50-59

logInfo @String $ "pubKeyUtxos:: " ++ show pubKeyUtxos

Expected Result

Wallets' utxos should be consistent.

Describe the approach you would take to fix this

No response

System info

a8540db

@catch-21 catch-21 added the bug Something isn't working label Sep 5, 2022
@koslambrou koslambrou added the Tracked Issue is tracked in our internal backlog label Sep 6, 2022
@berewt
Copy link
Contributor

berewt commented Oct 19, 2022

There is no bug, at least no reused TxOutIdx but we need to clarify the API: addressMap in diskState, contains a map the TxOutRef for all the Credentials, not only those of the given wallet. So we need to access the right entry of the map, and not take the head of its entries:

let trace :: Trace.EmulatorTrace () = do
        w1State <- Trace.agentState w1
        let cred = addressCredential $ Wallet.ownAddress w1State
             w1TxoRefs = w1State ^. chainIndexEmulatorState . diskState . addressMap . at cred . non mempty

berewt added a commit that referenced this issue Oct 25, 2022
* Fix the test(s) for bug 695

* Remove bug695 test

* Add solution to #695 to MustReferenceOutput / Remove #696 / harmonize tests

* Fix imports
kayvank pushed a commit that referenced this issue Oct 27, 2022
* Fix the test(s) for bug 695

* Remove bug695 test

* Add solution to #695 to MustReferenceOutput / Remove #696 / harmonize tests

* Fix imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Tracked Issue is tracked in our internal backlog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants