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

Update dApp tests to support the single-asset balance model. #81

Closed
Shaptic opened this issue Jan 9, 2023 · 2 comments
Closed

Update dApp tests to support the single-asset balance model. #81

Shaptic opened this issue Jan 9, 2023 · 2 comments
Labels
bug Something isn't working soroban-scrum A label to make relevant issues appear in the Platform Scrum board.

Comments

@Shaptic
Copy link
Contributor

Shaptic commented Jan 9, 2023

After #80, the tests still need to be updated.

Based on Discord threads (1 and 2), we need to manually create a LedgerSnapshot instance containing the xdr::TrustLineEntrys to the token admin for each of the participating accounts.

The following code gets part of the way there, but it relies on importing stellar_xdr as a separate crate, which conflicts with stellar_sdk::xdr, meaning the trustline entries can't actually be added to the entries vector due to differing types:

        // where `fxdr` comes from:
        //
        //    extern crate xdr as full_xdr;
        //    use full_xdr::next as fxdr;

        let token_admin = e.accounts().generate_and_create();

        let snap = e.to_snapshot();
        let entries = &snap.ledger_entries;

        for trustor in &std::vec![recipient, user1, user2] {
            let token_issuer = fxdr::AccountId(
                match TryInto::<xdr::AccountId>::try_into(token_admin).unwrap().0 {
                    xdr::PublicKey::PublicKeyTypeEd25519(pk) => {
                        fxdr::PublicKey::PublicKeyTypeEd25519(fxdr::Uint256(pk.0))
                    }
                },
            );

            let account_id = match TryInto::<xdr::AccountId>::try_into(trustor).unwrap().0 {
                xdr::PublicKey::PublicKeyTypeEd25519(pk) => {
                    fxdr::PublicKey::PublicKeyTypeEd25519(fxdr::Uint256(pk.0))
                }
            };

            let asset = fxdr::TrustLineAsset::CreditAlphanum4(fxdr::AlphaNum4 {
                asset_code: fxdr::AssetCode4([0x41; 4]),
                issuer: token_issuer,
            });

            let trustline = fxdr::LedgerKey::Trustline(fxdr::LedgerKeyTrustLine {
                account_id: fxdr::AccountId(account_id),
                asset,
            });

            let trustline_entry = (Box::new(key), Box::new(trustline));
            entries.push(trustline_entry);
        }

        snap.update_entries(&entries);
        e = soroban_sdk::Env::from_snapshot(snap);

Once stellar_sdk exposes all XDR types (or provides a convenient way to make trustlines), this can be modified to work.

@Shaptic Shaptic added the bug Something isn't working label Jan 9, 2023
@paulbellamy
Copy link
Contributor

Once fixed, we need to revert commit 56f5bef

@mollykarcher mollykarcher added the soroban-scrum A label to make relevant issues appear in the Platform Scrum board. label Apr 26, 2023
@esteblock
Copy link
Contributor

This issue should be marked as Closed @paulbellamy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working soroban-scrum A label to make relevant issues appear in the Platform Scrum board.
Projects
Status: Done
Development

No branches or pull requests

4 participants