stellar / soroban-example-dapp

End-to-End Example Soroban Dapp
Apache License 2.0
1.03k stars 835 forks source link

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

Closed Shaptic closed 1 year ago

Shaptic commented 1 year ago

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:

```rust // 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::::try_into(token_admin).unwrap().0 { xdr::PublicKey::PublicKeyTypeEd25519(pk) => { fxdr::PublicKey::PublicKeyTypeEd25519(fxdr::Uint256(pk.0)) } }, ); let account_id = match TryInto::::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.

paulbellamy commented 1 year ago

Once fixed, we need to revert commit https://github.com/stellar/soroban-example-dapp/pull/80/commits/56f5bef33da7cda9020b04ceef8877ed17c1ad3e

esteblock commented 1 year ago

This issue should be marked as Closed @paulbellamy