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

Fix: error, enum, union types #731

Conversation

willemneal
Copy link
Member

What

Upgrade to new error type and fix other types.

Why

[TODO: Why this change is being made. Include any context required to understand the why.]

Known limitations

Currently invoke.ts is failing because of xdr change.

Paul Bellamy and others added 30 commits June 23, 2023 17:22
@willemneal
Copy link
Member Author

@paulbellamy It's failing to find the xdr in the test wasms. Could there be a version mismatch? I'm very confused how this could happen.

Copy link
Contributor

@paulbellamy paulbellamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small suggestions, but looks fine.

Makefile Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
cmd/crates/soroban-test/tests/it/custom_types.rs Outdated Show resolved Hide resolved
@willemneal
Copy link
Member Author

willemneal commented Jun 30, 2023

The invoke.ts is failing on this line:

 const auth = SorobanClient.xdr.SorobanAuthorizationEntry.fromXDR(auths![0]!, 'base64')
    if (auth.addressWithNonce() !== undefined) {
      throw new NotImplementedError(
        `This transaction needs to be signed by ${auth.addressWithNonce()
        }; Not yet supported`
      )
    }

SorobanAuthorizationEntry does not seem to be defined. How is this done now?

@willemneal willemneal force-pushed the soroban-cli-auth-and-multi-invoke branch from 2dc3e56 to 3630239 Compare June 30, 2023 14:36
@paulbellamy
Copy link
Contributor

You probably need stellar/js-soroban-client#103, because that updates the XDR

@willemneal
Copy link
Member Author

Should we pause this PR until then? Or merge and make one just for updating that?

@kalepail
Copy link
Contributor

Is there a clean way to test this before preview 10 is live? I'd love for this typescript bindings thing to work well but I'm currently blocked on errors and apparently this PR may help me

@kalepail
Copy link
Contributor

Alright I did

cargo install --git https://github.com/AhaLabs/soroban-tools --rev 3630239df49f4f0cce2efb22f7ed5e9e4e23ef89 soroban-cli

which installed that commit for this PR however there are still a couple types errors I'm seeing:

Error 1

export async function colors_mine({ miner, to, colors }: { miner: Address, to: Option<Address>, colors: Array<[u32, u32]> }, { signAndSend, fee }: { signAndSend?: boolean, fee?: number } = { signAndSend: false, fee: 100 }): Promise<void> {
    let invokeArgs: InvokeArgs = {
        signAndSend,
        fee,
        method: 'colors_mine',
        args: [((i) => addressToScVal(i))(miner),
        ((i) => (!i) ? xdr.ScVal.scvVoid() : addressToScVal(i))(to),
        ((i) => xdr.ScVal.scvVec(i.map((i) => [
            ((i) => xdr.ScVal.scvU32(i))(i[0]),
            ((i) => xdr.ScVal.scvU32(i))(i[1])
        ])))(colors)],
    };

    // @ts-ignore Type does exist
    const response = await invoke(invokeArgs);
    return;
}

Screenshot 2023-06-30 at 2 38 53 PM

pub fn colors_mine(env: &Env, miner: Address, to: Option<Address>, colors: Vec<(u32, u32)>)

Error 2

export async function glyph_mint({ minter, to, colors, width }: { minter: Address, to: Option<Address>, colors: Array<[Address, Array<[u32, Array<u32>]>]>, width: u32 }, { signAndSend, fee }: { signAndSend?: boolean, fee?: number } = { signAndSend: false, fee: 100 }): Promise<Buffer> {
    let invokeArgs: InvokeArgs = {
        signAndSend,
        fee,
        method: 'glyph_mint',
        args: [((i) => addressToScVal(i))(minter),
        ((i) => (!i) ? xdr.ScVal.scvVoid() : addressToScVal(i))(to),
        ((i) => xdr.ScVal.scvVec(i.map((i) => [
            ((i) => addressToScVal(i))(i[0]),
            ((i) => xdr.ScVal.scvVec(i.map((i) => [
                ((i) => xdr.ScVal.scvU32(i))(i[0]),
                ((i) => xdr.ScVal.scvVec(i.map((i) => xdr.ScVal.scvU32(i))))(i[1])
            ])))(i[1])
        ])))(colors),
        ((i) => xdr.ScVal.scvU32(i))(width)],
    };

    // @ts-ignore Type does exist
    const response = await invoke(invokeArgs);
    return scValStrToJs(response.xdr) as Buffer;
}

Screenshot 2023-06-30 at 2 39 59 PM

pub fn glyph_mint(
    env: &Env,
    minter: Address,
    to: Option<Address>,
    colors: Vec<(Address, Vec<(u32, Vec<u32>)>)>,
    width: u32,
) -> BytesN<32>

Error 3

function GlyphToXdr(glyph?: Glyph): xdr.ScVal {
    if (!glyph) {
        return xdr.ScVal.scvVoid();
    }
    let arr = [
        new xdr.ScMapEntry({
            key: ((i) => xdr.ScVal.scvSymbol(i))("colors"), val: ((i) => xdr.ScVal.scvVec(i.map((i) => [
                ((i) => addressToScVal(i))(i[0]),
                ((i) => xdr.ScVal.scvVec(i.map((i) => [
                    ((i) => xdr.ScVal.scvU32(i))(i[0]),
                    ((i) => xdr.ScVal.scvVec(i.map((i) => xdr.ScVal.scvU32(i))))(i[1])
                ])))(i[1])
            ])))(glyph["colors"])
        }),
        new xdr.ScMapEntry({ key: ((i) => xdr.ScVal.scvSymbol(i))("length"), val: ((i) => xdr.ScVal.scvU32(i))(glyph["length"]) }),
        new xdr.ScMapEntry({ key: ((i) => xdr.ScVal.scvSymbol(i))("width"), val: ((i) => xdr.ScVal.scvU32(i))(glyph["width"]) })
    ];
    return xdr.ScVal.scvMap(arr);
}

Screenshot 2023-06-30 at 2 40 56 PM

@kalepail
Copy link
Contributor

Looks like we're just missing wrapping those bare arrays with a xdr.ScVal.scvVec.

@willemneal
Copy link
Member Author

@tyvdh Tuple structs should work now. It will take some more work and thought to update to use @Shaptic, but I think my future efforts should go in the stellar-base not here. However, in the interest of getting this done, I just kept it here.

@paulbellamy @tsachiherman Currently all tests pass, except the fetch test which is the only one that uses futurenet and it fails with:

Rpc(JsonRpc(Call(ErrorObject { code: InvalidParams, message: "cannot unmarshal key value AAAABgAAAAG8B08PA5NNAYllO8Fa+agxcEEeEDtMSKY4iDBs+6QayAAAABQAAAABAAAAAA== at index 0", data: None })))

Installing a contract to futurenet also has the issue of error: transaction simulation failed: Could not unmarshal transaction.

My guess is that the RPC hasn't been updated yet. But this makes me think we should improve the error messages if the version of the CLI differs from futurenet.

@tsachiherman
Copy link
Contributor

@willemneal , I think that for the purposes of our testing here, we shouldn't use any public network. These network conditions aren't deterministic and could cause non-useful results. Instead, we should run the futurenet tests after we've upgraded the network, as part of the smoke testing.

@tsachiherman tsachiherman merged commit 5b53678 into stellar:soroban-xdr-next Jul 5, 2023
@chadoh chadoh deleted the soroban-cli-auth-and-multi-invoke branch July 5, 2023 18:59
tsachiherman added a commit that referenced this pull request Jul 12, 2023
* update go dep xdr for preview 10

* update

* soroban-rpc: update code to latest XDR auth and single-function changes (#703)

* WIP

* WIP

* WIP

* Add clarification about events

* Moar progress

* Last compilation fixes

* progress

* Fix another test

* small cleanup

* Fix last test

* Fix more tests

* Fix more tests

* Fix another test

* Update to a working (if not the absolute latest) xdr

* updating xdr in preflight for fees & auth

* pass the min entry expiration into preflight

* rawval and set updates

* Fix udt test wasm

* rustfmt

* Updating txresult move

* use simon's core image build

* Get all rpc unit tests compiling (but not passing)

* fix up cargo toml rs-soroban-sdk import

* Fix ledgerentry test

* Fix getEvents test

* Fix GetTransactionTest

* Upgrade core version for integration tests

* Clean up integration tests

* Change the simulateTransactionResponse API back to make the changeover simpler for now

* Update integration tests expectations for simulateTransaction

* Missed one

---------

Co-authored-by: Paul Bellamy <paul@stellar.org>

* merge with main, and update the go monorepo link.

* soroban-rpc: Adapt Go and Rust code to the latest XDR changes (#724)

* Sync code with the latest XDR changes

* Bump rust and Core dependencies

* Update Rust code to the new sdk and env versions

* Fix test

* Fix ledgerentry tests for new xdr (#725)

* preview10: soroban-cli xdr updates (#722)

* StorageType support

* Fix VecM max lengths

* Fix LedgerKeyNonce conversion

* partial ScStatus -> ScError updates

* Working on updating for new contract code and entry storage

* updating for new xdr

* update rs-soroban-sdk to commit e90db9f8009280516375df6b3ee43a65ff524577

* Updating xdr again

* New token spec location

* Cargo fmt

* Fix binding-generators

* Dig out the new invokeHostFunction return value

* Fix up last of the build

* Clippy shenanigans

* use symbol_short macro

* Set signature_expiration_ledger for sandbox

* fixup! use symbol_short macro

* fixup! Set signature_expiration_ledger for sandbox

* Clean up a vague error

* set expiration on contract codes in sandbox

* Set expiration on contract instances on sandbox

* Handle expired contract code ledger entries in the sandbox

* Include temporary entries from contract read subcommand

* Implement ledger entry expiration bumps in sandbox

* cargo md-gen

* Fix rpc simulateTransaction client tests

* Merge origin/main into soroban-xdr-next (#728)

* soroban-rpc: bug workaround and test fixes (#726)

* updated rs-env and mono repo versions (#741)

* updated rs-env for 0.9. and mono repo with latest xdr gen updates

* review feedback, fix go ref to soroban-xdr-next-next

* update all workspace rs-sdk refs to same in toml

* updated the cargo ver to match the gh ref

* included cargo.lock and deps check fix

* soroban-rpc: Implement preflighting of BumpFootprintExpiration and RestoreFootprint operations (#730)

* sync with main (#744)

* Fix check-dependencies typos (#723)

* Add lab token id command (#693)

* Add lab token id command

* fix doc

* Keep only the strkey id

* refactoring

---------

Co-authored-by: Paul Bellamy <paul@stellar.org>

* fix(bindings-ts): don't delete existing dirs (#733)

* fix(bindings-ts): don't delete existing dirs

- Rename `root-dir` to `output-dir` to clarify the intent
- If `output-dir` already exists, use `output-dir/contract-name` instead

* docs: update auto-generated

* Upgrade wasm-opt to 0.113 (#736)

* fix

* fix

* update

* cargo fmt

---------

Co-authored-by: Alfonso Acosta <alfonso@stellar.org>
Co-authored-by: Vincent Amouret <vincent.amouret@gmail.com>
Co-authored-by: Paul Bellamy <paul@stellar.org>
Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com>
Co-authored-by: Brian Anderson <andersrb@gmail.com>

* Fix bug loading contract spec in sandbox when not deployed (#745)

* Fix check-dependencies typos (#723)

* Add lab token id command (#693)

* Add lab token id command

* fix doc

* Keep only the strkey id

* refactoring

---------

Co-authored-by: Paul Bellamy <paul@stellar.org>

* fix(bindings-ts): don't delete existing dirs (#733)

* fix(bindings-ts): don't delete existing dirs

- Rename `root-dir` to `output-dir` to clarify the intent
- If `output-dir` already exists, use `output-dir/contract-name` instead

* docs: update auto-generated

* Upgrade wasm-opt to 0.113 (#736)

* fix

* fix

* update

* cargo fmt

* Fix bug loading contract spec in sandbox when not deployed

* Make fmt

* No more 'set' type to test

* remove unused import

* Fix sandbox contract invoke

* Make test invoke quiet so it doesn't spit out events

* Set default state expiries in the sandbox

* Add a note about a crappy test

---------

Co-authored-by: Alfonso Acosta <alfonso@stellar.org>
Co-authored-by: Vincent Amouret <vincent.amouret@gmail.com>
Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com>
Co-authored-by: Brian Anderson <andersrb@gmail.com>
Co-authored-by: Tsachi Herman <24438559+tsachiherman@users.noreply.github.com>

* soroban-rpc: State Expiration (#695)

* Update go for new xdr

* WIP -- working on extensions

* Implement ExtendLedgerEntry

* Disallow access to expired ledgerEntries

* update go dep

* Include current ledger in expiry

* update ledgerEntry tests for new xdr

* Add unit test for ExtendEntry

* Add test for extending a non-existent ledger entry

* Add tests for expired contract entries

* Test creating and extending in the same batch

* Show expired ledger entries now that core will autobump

* Revert "Show expired ledger entries now that core will autobump"

This reverts commit b1426a7.

* Refactor expiry checking

* Replace assert.NotNil with require.NotNil

* Clearer naming

* better test error checking

* Add validation on upserting ledger entrys that the key matches

* Simplify UpsertLedgerEntry since key is derived from the entry

* Update go dependency to 3f69f56e3743bbd520e4c25f44b8fc49b1b81936

* soroban-rpc: Fix integration test phrasing (#747)

* soroban-rpc: Fix phrasing in an integration test

* fix typo

* Fix: error, enum, union types (#731)

* StorageType support

* Fix VecM max lengths

* Fix LedgerKeyNonce conversion

* partial ScStatus -> ScError updates

* Working on updating for new contract code and entry storage

* updating for new xdr

* update rs-soroban-sdk to commit e90db9f8009280516375df6b3ee43a65ff524577

* Updating xdr again

* New token spec location

* Cargo fmt

* Fix binding-generators

* Dig out the new invokeHostFunction return value

* Fix up last of the build

* Clippy shenanigans

* use symbol_short macro

* Set signature_expiration_ledger for sandbox

* fixup! use symbol_short macro

* fixup! Set signature_expiration_ledger for sandbox

* Clean up a vague error

* set expiration on contract codes in sandbox

* Set expiration on contract instances on sandbox

* Handle expired contract code ledger entries in the sandbox

* Include temporary entries from contract read subcommand

* Implement ledger entry expiration bumps in sandbox

* cargo md-gen

* Fix rpc simulateTransaction client tests

* fix: tuples and enums/unions and new Error type

* chore: pr review

* pull in some fixes

* tuples are friends not food

* fix: update example inputs to instruct a tuple struct

* feat: add tuple struct support

* fix: update to use new bindings out-dir

---------

Co-authored-by: Paul Bellamy <paul@stellar.org>
Co-authored-by: Tyler van der Hoeven <hi@tyvdh.com>

* cargo fmt

* compile: disable the fetch test (#750)

* disable the fetch test, since it's testing it against futurenet.

* update boilerplate test.

* Fix bug in cli lab xdr decode --type parsing (#751)

* soroban-cli: Verify the network passphrase provided matches the server (#754)

* soroban-cli: fix contract deploy (#755)

* Fix return type parsing from soroban-rpc

* soroban-cli: Fix how contract code hashes are calculated

* Fix integration test

* Bump version to 0.9.0 (#758)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* soroban-rpc: Add bump footprint test (#746)

* Bump Core version (#759)

* update (#760)

* soroban-rpc: Restore footprint fixes (#761)

* update e2e tests (#762)

* update

* update

* update package.json to use the official js-soroban-client tag instead of an arbitrary commit hash..

* rollback package changes.

* really rollback.

* soroban-cli: Add super basic `contract bump` and `contract restore` subcommands (#748)

* add contract read --durability filter

* Add soroban contract bump subcommand

* Add soroban contract restore command

* Add support for restoring multiple keys at once

* cargo md-gen

* Clean up an unused error

* Need to increment the account sequence for bump+restore

* no --ledgers-to-expire for restore command

* Support bump+restore commands in preflight+transaction::assemble

* rust fmt

* cargo md-gen

* Require --durability for bump because the default is confusing

* Fix clippy

* cargo md-gen

* soroban-cli: Implement soroban contract read with real rpc support (#756)

* add contract read --durability filter

* Add soroban contract bump subcommand

* Add soroban contract restore command

* Add support for restoring multiple keys at once

* cargo md-gen

* implement soroban contract read with a real network

* Clean up an unused error

* Make fmt

* cargo md-gen

* getLedgerEntries.results can be null

* Need to increment the account sequence for bump+restore

* no --ledgers-to-expire for restore command

* Support bump+restore commands in preflight+transaction::assemble

* rust fmt

* cargo md-gen

* Require --durability for bump because the default is confusing

* Fix clippy

* cargo md-gen

---------

Co-authored-by: Tsachi Herman <24438559+tsachiherman@users.noreply.github.com>

* update e2e tests (#765)

* update

* update hash -> 0.9.0

---------

Co-authored-by: Tsachi Herman <24438559+tsachiherman@users.noreply.github.com>
Co-authored-by: Alfonso Acosta <alfonso@stellar.org>
Co-authored-by: shawn <sreuland@users.noreply.github.com>
Co-authored-by: Vincent Amouret <vincent.amouret@gmail.com>
Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com>
Co-authored-by: Brian Anderson <andersrb@gmail.com>
Co-authored-by: Willem Wyndham <willem@ahalabs.dev>
Co-authored-by: Tyler van der Hoeven <hi@tyvdh.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants