From 0347069b9af6bd0374c7079de4876a4f070c1455 Mon Sep 17 00:00:00 2001 From: hayes-mysten <135670682+hayes-mysten@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:49:55 -0700 Subject: [PATCH] =?UTF-8?q?[sdk]=20stop=20re-using=20gas=20coins=20that=20?= =?UTF-8?q?get=20used=20by=20other=20commands=20in=20para=E2=80=A6=20(#184?= =?UTF-8?q?12)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …llel executor ## Description Describe the changes or additions included in this PR. ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: --- .changeset/tall-points-decide.md | 5 ++ .../data/entry_point_types/Move.lock | 2 +- .../data/entry_point_vector/Move.lock | 2 +- .../src/transactions/executor/parallel.ts | 12 +++- sdk/typescript/test/e2e/coin-metadata.test.ts | 11 ++-- sdk/typescript/test/e2e/coin-read.test.ts | 6 +- .../test/e2e/coin-with-balance.test.ts | 11 ++-- .../test/e2e/data/coin_metadata/Move.lock | 2 +- .../coin_metadata/sources/coin_metadata.move | 1 - .../test/e2e/data/demo-bear/Move.toml | 10 ++++ .../e2e/data/demo-bear/sources/demo_bear.move | 58 +++++++++++++++++++ .../display_test/sources/display_test.move | 4 +- .../test/e2e/data/dynamic_fields/Move.lock | 2 +- .../sources/dynamic_fields.move | 2 - .../test/e2e/data/id_entry_args/Move.lock | 2 +- .../id_entry_args/sources/id_entry_args.move | 3 - .../test/e2e/data/serializer/Move.lock | 2 +- .../data/serializer/sources/serializer.move | 3 - .../sources/serializer.move | 3 - .../test/e2e/data/tto/sources/tto1.move | 2 - sdk/typescript/test/e2e/dev-inspect.test.ts | 6 +- .../test/e2e/dynamic-fields.test.ts | 6 +- sdk/typescript/test/e2e/id-entry-args.test.ts | 6 +- sdk/typescript/test/e2e/object-cache.test.ts | 8 +-- .../test/e2e/object-display-standard.test.ts | 6 +- .../test/e2e/parallel-executor.test.ts | 15 +++-- .../test/e2e/receive-object.test.ts | 8 +-- sdk/typescript/test/e2e/utils/setup.ts | 53 ++++++++++++++++- 28 files changed, 187 insertions(+), 64 deletions(-) create mode 100644 .changeset/tall-points-decide.md create mode 100644 sdk/typescript/test/e2e/data/demo-bear/Move.toml create mode 100644 sdk/typescript/test/e2e/data/demo-bear/sources/demo_bear.move diff --git a/.changeset/tall-points-decide.md b/.changeset/tall-points-decide.md new file mode 100644 index 00000000000000..88f04eebb8f902 --- /dev/null +++ b/.changeset/tall-points-decide.md @@ -0,0 +1,5 @@ +--- +'@mysten/sui': patch +--- + +Parallel executor now only re-uses gasCoins if the gas coin is only used for gas diff --git a/crates/sui-core/src/unit_tests/data/entry_point_types/Move.lock b/crates/sui-core/src/unit_tests/data/entry_point_types/Move.lock index bc55b179ad8fe4..6fd64473f7d5cb 100644 --- a/crates/sui-core/src/unit_tests/data/entry_point_types/Move.lock +++ b/crates/sui-core/src/unit_tests/data/entry_point_types/Move.lock @@ -22,6 +22,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.27.0" +compiler-version = "1.29.0" edition = "2024.beta" flavor = "sui" diff --git a/crates/sui-core/src/unit_tests/data/entry_point_vector/Move.lock b/crates/sui-core/src/unit_tests/data/entry_point_vector/Move.lock index b9d7dd3233d8a2..e33f835f807033 100644 --- a/crates/sui-core/src/unit_tests/data/entry_point_vector/Move.lock +++ b/crates/sui-core/src/unit_tests/data/entry_point_vector/Move.lock @@ -22,6 +22,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.27.0" +compiler-version = "1.29.0" edition = "2024.beta" flavor = "sui" diff --git a/sdk/typescript/src/transactions/executor/parallel.ts b/sdk/typescript/src/transactions/executor/parallel.ts index 5f97084847f7bc..d0fd55d86a303e 100644 --- a/sdk/typescript/src/transactions/executor/parallel.ts +++ b/sdk/typescript/src/transactions/executor/parallel.ts @@ -9,6 +9,7 @@ import type { SuiClient } from '../../client/index.js'; import type { Signer } from '../../cryptography/index.js'; import type { ObjectCacheOptions } from '../ObjectCache.js'; import { Transaction } from '../Transaction.js'; +import { TransactionDataBuilder } from '../TransactionData.js'; import { CachingTransactionExecutor } from './caching.js'; import { ParallelQueue, SerialQueue } from './queue.js'; import { getGasCoinFromEffects } from './serial.js'; @@ -225,7 +226,16 @@ export class ParallelTransactionExecutor { BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate); - if (gasCoin.balance >= this.#minimumCoinBalance) { + let usesGasCoin = false; + new TransactionDataBuilder(transaction.getData()).mapArguments((arg) => { + if (arg.$kind === 'GasCoin') { + usesGasCoin = true; + } + + return arg; + }); + + if (!usesGasCoin && gasCoin.balance >= this.#minimumCoinBalance) { this.#coinPool.push({ id: gasResult.ref.objectId, version: gasResult.ref.version, diff --git a/sdk/typescript/test/e2e/coin-metadata.test.ts b/sdk/typescript/test/e2e/coin-metadata.test.ts index 152e46c08266d1..978122c55cf47a 100644 --- a/sdk/typescript/test/e2e/coin-metadata.test.ts +++ b/sdk/typescript/test/e2e/coin-metadata.test.ts @@ -1,18 +1,19 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import { beforeEach, describe, expect, it } from 'vitest'; +import { resolve } from 'path'; +import { beforeAll, describe, expect, it } from 'vitest'; -import { publishPackage, setup, TestToolbox } from './utils/setup'; +import { setup, TestToolbox } from './utils/setup'; describe('Test Coin Metadata', () => { let toolbox: TestToolbox; let packageId: string; - beforeEach(async () => { + beforeAll(async () => { toolbox = await setup(); - const packagePath = __dirname + '/./data/coin_metadata'; - ({ packageId } = await publishPackage(packagePath)); + const packagePath = resolve(__dirname, './data/coin_metadata'); + packageId = await toolbox.getPackage(packagePath); }); it('Test accessing coin metadata', async () => { diff --git a/sdk/typescript/test/e2e/coin-read.test.ts b/sdk/typescript/test/e2e/coin-read.test.ts index 203564bba1c273..2104f34b15883d 100644 --- a/sdk/typescript/test/e2e/coin-read.test.ts +++ b/sdk/typescript/test/e2e/coin-read.test.ts @@ -1,9 +1,10 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { resolve } from 'path'; import { beforeAll, describe, expect, it } from 'vitest'; -import { publishPackage, setup, TestToolbox } from './utils/setup'; +import { setup, TestToolbox } from './utils/setup'; describe('CoinRead API', () => { let toolbox: TestToolbox; @@ -13,8 +14,7 @@ describe('CoinRead API', () => { beforeAll(async () => { [toolbox, publishToolbox] = await Promise.all([setup(), setup()]); - const packagePath = __dirname + '/./data/coin_metadata'; - ({ packageId } = await publishPackage(packagePath, publishToolbox)); + packageId = await publishToolbox.getPackage(resolve(__dirname, './data/coin_metadata')); testType = packageId + '::test::TEST'; }); diff --git a/sdk/typescript/test/e2e/coin-with-balance.test.ts b/sdk/typescript/test/e2e/coin-with-balance.test.ts index 85240a9514b2d4..0e15b69d954b86 100644 --- a/sdk/typescript/test/e2e/coin-with-balance.test.ts +++ b/sdk/typescript/test/e2e/coin-with-balance.test.ts @@ -1,15 +1,16 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { resolve } from 'path'; import { fromHEX, toB64 } from '@mysten/bcs'; -import { beforeEach, describe, expect, it } from 'vitest'; +import { beforeAll, describe, expect, it } from 'vitest'; import { bcs } from '../../src/bcs'; import { Ed25519Keypair } from '../../src/keypairs/ed25519'; import { Transaction } from '../../src/transactions'; import { coinWithBalance } from '../../src/transactions/intents/CoinWithBalance'; import { normalizeSuiAddress } from '../../src/utils'; -import { publishPackage, setup, TestToolbox } from './utils/setup'; +import { setup, TestToolbox } from './utils/setup'; describe('coinWithBalance', () => { let toolbox: TestToolbox; @@ -17,10 +18,10 @@ describe('coinWithBalance', () => { let packageId: string; let testType: string; - beforeEach(async () => { + beforeAll(async () => { [toolbox, publishToolbox] = await Promise.all([setup(), setup()]); - const packagePath = __dirname + '/./data/coin_metadata'; - ({ packageId } = await publishPackage(packagePath, publishToolbox)); + const packagePath = resolve(__dirname, './data/coin_metadata'); + packageId = await publishToolbox.getPackage(packagePath); testType = normalizeSuiAddress(packageId) + '::test::TEST'; }); diff --git a/sdk/typescript/test/e2e/data/coin_metadata/Move.lock b/sdk/typescript/test/e2e/data/coin_metadata/Move.lock index 24cecd492bd40e..244dd6e142ce2c 100644 --- a/sdk/typescript/test/e2e/data/coin_metadata/Move.lock +++ b/sdk/typescript/test/e2e/data/coin_metadata/Move.lock @@ -22,6 +22,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.27.0" +compiler-version = "1.29.0" edition = "2024.beta" flavor = "sui" diff --git a/sdk/typescript/test/e2e/data/coin_metadata/sources/coin_metadata.move b/sdk/typescript/test/e2e/data/coin_metadata/sources/coin_metadata.move index 398564407c41f0..d547669973fd1b 100644 --- a/sdk/typescript/test/e2e/data/coin_metadata/sources/coin_metadata.move +++ b/sdk/typescript/test/e2e/data/coin_metadata/sources/coin_metadata.move @@ -6,7 +6,6 @@ module coin_metadata::test { use sui::coin; use sui::transfer; use sui::url; - use sui::tx_context::{Self, TxContext}; public struct TEST has drop {} diff --git a/sdk/typescript/test/e2e/data/demo-bear/Move.toml b/sdk/typescript/test/e2e/data/demo-bear/Move.toml new file mode 100644 index 00000000000000..7bc306fbfd31f6 --- /dev/null +++ b/sdk/typescript/test/e2e/data/demo-bear/Move.toml @@ -0,0 +1,10 @@ +[package] +name = "demo" +version = "0.0.1" +edition = "2024.beta" + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } + +[addresses] +demo = "0x0" diff --git a/sdk/typescript/test/e2e/data/demo-bear/sources/demo_bear.move b/sdk/typescript/test/e2e/data/demo-bear/sources/demo_bear.move new file mode 100644 index 00000000000000..1f45573ac32b09 --- /dev/null +++ b/sdk/typescript/test/e2e/data/demo-bear/sources/demo_bear.move @@ -0,0 +1,58 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +module demo::demo_bear { + use std::string::{String, utf8}; + + use sui::package; + use sui::display; + + /// our demo struct. + public struct DemoBear has key, store { + id: UID, + name: String + } + + /// our OTW to create display. + public struct DEMO_BEAR has drop {} + + // It's recommened to create Display using PTBs instead of + // directly on the contracts. + // We are only creating it here for demo purposes (one-step setup). + fun init(otw: DEMO_BEAR, ctx: &mut TxContext){ + let publisher = package::claim(otw, ctx); + let keys = vector[ + utf8(b"name"), + utf8(b"image_url"), + utf8(b"description"), + ]; + + + let values = vector[ + // Let's add a demo name for our `DemoBear` + utf8(b"{name}"), + // Adding a happy bear image. + utf8(b"https://images.unsplash.com/photo-1589656966895-2f33e7653819?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8cG9sYXIlMjBiZWFyfGVufDB8fDB8fHww"), + // Description is static for all bears out there. + utf8(b"The greatest figure for demos"), + ]; + + // Get a new `Display` object for the `Hero` type. + let mut display = display::new_with_fields( + &publisher, keys, values, ctx + ); + + // Commit first version of `Display` to apply changes. + display::update_version(&mut display); + + sui::transfer::public_transfer(display, ctx.sender()); + sui::transfer::public_transfer(publisher, ctx.sender()) + } + + public fun new(name: String, ctx: &mut TxContext): DemoBear { + DemoBear { + id: object::new(ctx), + name: name + } + } +} diff --git a/sdk/typescript/test/e2e/data/display_test/sources/display_test.move b/sdk/typescript/test/e2e/data/display_test/sources/display_test.move index 9865846e0c2da5..ef097c0c3aeea0 100644 --- a/sdk/typescript/test/e2e/data/display_test/sources/display_test.move +++ b/sdk/typescript/test/e2e/data/display_test/sources/display_test.move @@ -2,9 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 module display_test::boars { - use sui::object::{Self, UID}; - use std::option::{Self, Option}; - use sui::tx_context::{TxContext, sender}; + use sui::tx_context::{sender}; use sui::transfer; use sui::package; use sui::url::{Self, Url}; diff --git a/sdk/typescript/test/e2e/data/dynamic_fields/Move.lock b/sdk/typescript/test/e2e/data/dynamic_fields/Move.lock index a865fabd53bf7b..1e028e87a1514f 100644 --- a/sdk/typescript/test/e2e/data/dynamic_fields/Move.lock +++ b/sdk/typescript/test/e2e/data/dynamic_fields/Move.lock @@ -22,6 +22,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.27.0" +compiler-version = "1.29.0" edition = "2024.beta" flavor = "sui" diff --git a/sdk/typescript/test/e2e/data/dynamic_fields/sources/dynamic_fields.move b/sdk/typescript/test/e2e/data/dynamic_fields/sources/dynamic_fields.move index 263d58fa226954..9bb36e35bbcd07 100644 --- a/sdk/typescript/test/e2e/data/dynamic_fields/sources/dynamic_fields.move +++ b/sdk/typescript/test/e2e/data/dynamic_fields/sources/dynamic_fields.move @@ -4,8 +4,6 @@ module dynamic_fields::dynamic_fields_test { use sui::dynamic_field as dfield; use sui::dynamic_object_field as dof; - use sui::object::{Self, UID}; - use sui::tx_context::{Self, TxContext}; use sui::transfer; public struct Test has key { diff --git a/sdk/typescript/test/e2e/data/id_entry_args/Move.lock b/sdk/typescript/test/e2e/data/id_entry_args/Move.lock index 900584a2c2bfe7..f87fdc0f07c5b1 100644 --- a/sdk/typescript/test/e2e/data/id_entry_args/Move.lock +++ b/sdk/typescript/test/e2e/data/id_entry_args/Move.lock @@ -22,6 +22,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.27.0" +compiler-version = "1.29.0" edition = "2024.beta" flavor = "sui" diff --git a/sdk/typescript/test/e2e/data/id_entry_args/sources/id_entry_args.move b/sdk/typescript/test/e2e/data/id_entry_args/sources/id_entry_args.move index bb7e16e6179709..8c5f2c2c923e1a 100644 --- a/sdk/typescript/test/e2e/data/id_entry_args/sources/id_entry_args.move +++ b/sdk/typescript/test/e2e/data/id_entry_args/sources/id_entry_args.move @@ -2,9 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 module id_entry_args::test { - use sui::tx_context::TxContext; - use sui::object::{Self, ID}; - public entry fun test_id(id: ID, _ctx: &mut TxContext) { assert!(object::id_to_address(&id) == @0xc2b5625c221264078310a084df0a3137956d20ee, 0); } diff --git a/sdk/typescript/test/e2e/data/serializer/Move.lock b/sdk/typescript/test/e2e/data/serializer/Move.lock index 92f6d72863a187..3d68ec230f855c 100644 --- a/sdk/typescript/test/e2e/data/serializer/Move.lock +++ b/sdk/typescript/test/e2e/data/serializer/Move.lock @@ -22,6 +22,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.27.0" +compiler-version = "1.29.0" edition = "2024.beta" flavor = "sui" diff --git a/sdk/typescript/test/e2e/data/serializer/sources/serializer.move b/sdk/typescript/test/e2e/data/serializer/sources/serializer.move index 6c6b6b0859e399..d990ce1ac5bef7 100644 --- a/sdk/typescript/test/e2e/data/serializer/sources/serializer.move +++ b/sdk/typescript/test/e2e/data/serializer/sources/serializer.move @@ -2,9 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 module serializer::serializer_tests { - use sui::tx_context::{Self, TxContext}; - use sui::transfer; - use sui::object::{Self, UID}; use sui::clock::Clock; use std::option::Option; use sui::object::ID; diff --git a/sdk/typescript/test/e2e/data/serializer_upgrade/sources/serializer.move b/sdk/typescript/test/e2e/data/serializer_upgrade/sources/serializer.move index 35d1c895ddb85b..cf34cd3659f083 100644 --- a/sdk/typescript/test/e2e/data/serializer_upgrade/sources/serializer.move +++ b/sdk/typescript/test/e2e/data/serializer_upgrade/sources/serializer.move @@ -2,12 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 module serializer::serializer_tests { - use sui::tx_context::{Self, TxContext}; use sui::transfer; - use sui::object::{Self, UID}; use sui::clock::Clock; use std::option::Option; - use sui::object::ID; use std::string::String; use std::ascii; diff --git a/sdk/typescript/test/e2e/data/tto/sources/tto1.move b/sdk/typescript/test/e2e/data/tto/sources/tto1.move index 3c98e96910e797..d1d48e5de281c5 100644 --- a/sdk/typescript/test/e2e/data/tto/sources/tto1.move +++ b/sdk/typescript/test/e2e/data/tto/sources/tto1.move @@ -2,8 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 module tto::tto { - use sui::object::{Self, UID}; - use sui::tx_context::{Self, TxContext}; use sui::transfer::{Self, Receiving}; public struct A has key, store { diff --git a/sdk/typescript/test/e2e/dev-inspect.test.ts b/sdk/typescript/test/e2e/dev-inspect.test.ts index 93f2d61618d281..db02f716a6e45b 100644 --- a/sdk/typescript/test/e2e/dev-inspect.test.ts +++ b/sdk/typescript/test/e2e/dev-inspect.test.ts @@ -1,12 +1,13 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { resolve } from 'path'; import { beforeAll, describe, expect, it } from 'vitest'; import { SuiClient } from '../../src/client'; import { Keypair } from '../../src/cryptography'; import { Transaction } from '../../src/transactions'; -import { publishPackage, setup, TestToolbox } from './utils/setup'; +import { setup, TestToolbox } from './utils/setup'; describe('Test dev inspect', () => { let toolbox: TestToolbox; @@ -14,8 +15,7 @@ describe('Test dev inspect', () => { beforeAll(async () => { toolbox = await setup(); - const packagePath = __dirname + '/./data/serializer'; - ({ packageId } = await publishPackage(packagePath)); + packageId = await toolbox.getPackage(resolve(__dirname, './data/serializer')); }); it('Dev inspect split + transfer', async () => { diff --git a/sdk/typescript/test/e2e/dynamic-fields.test.ts b/sdk/typescript/test/e2e/dynamic-fields.test.ts index 916ebc7c8829fa..a23065b45bbdc3 100644 --- a/sdk/typescript/test/e2e/dynamic-fields.test.ts +++ b/sdk/typescript/test/e2e/dynamic-fields.test.ts @@ -1,10 +1,11 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { resolve } from 'path'; import { beforeAll, describe, expect, it } from 'vitest'; import { SuiObjectData } from '../../src/client'; -import { publishPackage, setup, TestToolbox } from './utils/setup'; +import { setup, TestToolbox } from './utils/setup'; describe('Dynamic Fields Reading API', () => { let toolbox: TestToolbox; @@ -13,8 +14,7 @@ describe('Dynamic Fields Reading API', () => { beforeAll(async () => { toolbox = await setup(); - const packagePath = __dirname + '/./data/dynamic_fields'; - ({ packageId } = await publishPackage(packagePath, toolbox)); + packageId = await toolbox.getPackage(resolve(__dirname, './data/dynamic_fields')); await toolbox.client .getOwnedObjects({ diff --git a/sdk/typescript/test/e2e/id-entry-args.test.ts b/sdk/typescript/test/e2e/id-entry-args.test.ts index 7c46432977eaeb..afa9d960cd9055 100644 --- a/sdk/typescript/test/e2e/id-entry-args.test.ts +++ b/sdk/typescript/test/e2e/id-entry-args.test.ts @@ -1,10 +1,11 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { resolve } from 'path'; import { beforeAll, describe, expect, it } from 'vitest'; import { Transaction } from '../../src/transactions'; -import { publishPackage, setup, TestToolbox } from './utils/setup'; +import { setup, TestToolbox } from './utils/setup'; describe('Test ID as args to entry functions', () => { let toolbox: TestToolbox; @@ -12,8 +13,7 @@ describe('Test ID as args to entry functions', () => { beforeAll(async () => { toolbox = await setup(); - const packagePath = __dirname + '/./data/id_entry_args'; - ({ packageId } = await publishPackage(packagePath)); + packageId = await toolbox.getPackage(resolve(__dirname, './data/id_entry_args')); }); it('Test ID as arg to entry functions', async () => { diff --git a/sdk/typescript/test/e2e/object-cache.test.ts b/sdk/typescript/test/e2e/object-cache.test.ts index a50f59c61775b4..3aa38cbf33503d 100644 --- a/sdk/typescript/test/e2e/object-cache.test.ts +++ b/sdk/typescript/test/e2e/object-cache.test.ts @@ -1,13 +1,14 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { resolve } from 'path'; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { OwnedObjectRef } from '../../src/client'; import { Transaction } from '../../src/transactions'; import { CachingTransactionExecutor } from '../../src/transactions/executor/caching'; import { normalizeSuiAddress } from '../../src/utils'; -import { publishPackage, setup, TestToolbox } from './utils/setup'; +import { setup, TestToolbox } from './utils/setup'; describe('CachingTransactionExecutor', async () => { let toolbox: TestToolbox; @@ -18,13 +19,12 @@ describe('CachingTransactionExecutor', async () => { let receiveObjectId: OwnedObjectRef; beforeAll(async () => { - const packagePath = __dirname + '/./data/tto'; - rawPackageId = (await publishPackage(packagePath)).packageId; + toolbox = await setup(); + rawPackageId = packageId = await toolbox.getPackage(resolve(__dirname, './data/tto')); packageId = normalizeSuiAddress(rawPackageId); }); beforeEach(async () => { - toolbox = await setup(); executor = new CachingTransactionExecutor({ client: toolbox.client, }); diff --git a/sdk/typescript/test/e2e/object-display-standard.test.ts b/sdk/typescript/test/e2e/object-display-standard.test.ts index 835cbf9e098ee1..75b17e37ac8906 100644 --- a/sdk/typescript/test/e2e/object-display-standard.test.ts +++ b/sdk/typescript/test/e2e/object-display-standard.test.ts @@ -1,10 +1,11 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { resolve } from 'path'; import { beforeAll, describe, expect, it } from 'vitest'; import { SuiObjectData } from '../../src/client'; -import { publishPackage, setup, TestToolbox } from './utils/setup'; +import { setup, TestToolbox } from './utils/setup'; describe('Test Object Display Standard', () => { let toolbox: TestToolbox; @@ -12,8 +13,7 @@ describe('Test Object Display Standard', () => { beforeAll(async () => { toolbox = await setup(); - const packagePath = __dirname + '/./data/display_test'; - ({ packageId } = await publishPackage(packagePath, toolbox)); + packageId = await toolbox.getPackage(resolve(__dirname, './data/display_test')); }); it('Test getting Display fields with error object', async () => { diff --git a/sdk/typescript/test/e2e/parallel-executor.test.ts b/sdk/typescript/test/e2e/parallel-executor.test.ts index f81cc1f3812d13..850a27c6994987 100644 --- a/sdk/typescript/test/e2e/parallel-executor.test.ts +++ b/sdk/typescript/test/e2e/parallel-executor.test.ts @@ -11,8 +11,13 @@ import { setup, TestToolbox } from './utils/setup'; let toolbox: TestToolbox; let executor: ParallelTransactionExecutor; + beforeAll(async () => { toolbox = await setup(); + + // Creates bear package + await toolbox.mintNft(); + executor = new ParallelTransactionExecutor({ client: toolbox.client, signer: toolbox.keypair, @@ -54,11 +59,13 @@ describe('ParallelTransactionExecutor', () => { }); }); - const txbs = Array.from({ length: 10 }, () => { + const txbs = []; + + for (let i = 0; i < 10; i++) { const txb = new Transaction(); - txb.transferObjects([txb.splitCoins(txb.gas, [1])[0]], toolbox.address()); - return txb; - }); + txb.transferObjects([await toolbox.mintNft()], toolbox.address()); + txbs.push(txb); + } const results = await Promise.all(txbs.map((txb) => executor.executeTransaction(txb))); diff --git a/sdk/typescript/test/e2e/receive-object.test.ts b/sdk/typescript/test/e2e/receive-object.test.ts index b851d25720dabf..90ba0bff5a6180 100644 --- a/sdk/typescript/test/e2e/receive-object.test.ts +++ b/sdk/typescript/test/e2e/receive-object.test.ts @@ -1,12 +1,13 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { resolve } from 'path'; import { beforeAll, beforeEach, describe, expect, it } from 'vitest'; import { OwnedObjectRef, SuiClient } from '../../src/client'; import type { Keypair } from '../../src/cryptography'; import { Transaction } from '../../src/transactions'; -import { publishPackage, setup, TestToolbox } from './utils/setup'; +import { setup, TestToolbox } from './utils/setup'; function getOwnerAddress(o: OwnedObjectRef): string | undefined { // const owner = getObjectOwner(o); @@ -25,12 +26,11 @@ describe('Transfer to Object', () => { let sharedObjectId: string; beforeAll(async () => { - const packagePath = __dirname + '/./data/tto'; - ({ packageId } = await publishPackage(packagePath)); + toolbox = await setup(); + packageId = await toolbox.getPackage(resolve(__dirname, './data/tto')); }); beforeEach(async () => { - toolbox = await setup(); const tx = new Transaction(); tx.moveCall({ target: `${packageId}::tto::start`, diff --git a/sdk/typescript/test/e2e/utils/setup.ts b/sdk/typescript/test/e2e/utils/setup.ts index 4025ecef5259ff..18a825b42c0435 100644 --- a/sdk/typescript/test/e2e/utils/setup.ts +++ b/sdk/typescript/test/e2e/utils/setup.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { execSync } from 'child_process'; +import { resolve } from 'path'; import tmp from 'tmp'; import { retry } from 'ts-retry-promise'; import { expect } from 'vitest'; @@ -31,13 +32,45 @@ export const DEFAULT_RECIPIENT_2 = export const DEFAULT_GAS_BUDGET = 10000000; export const DEFAULT_SEND_AMOUNT = 1000; +class TestPackageRegistry { + static registries: Map = new Map(); + + static forUrl(url: string) { + if (!this.registries.has(url)) { + this.registries.set(url, new TestPackageRegistry()); + } + return this.registries.get(url)!; + } + + #packages: Map; + + constructor() { + this.#packages = new Map(); + } + + async getPackage(path: string, toolbox?: TestToolbox) { + if (!this.#packages.has(path)) { + this.#packages.set(path, (await publishPackage(path, toolbox)).packageId); + } + + return this.#packages.get(path)!; + } +} + export class TestToolbox { keypair: Ed25519Keypair; client: SuiClient; + registry: TestPackageRegistry; - constructor(keypair: Ed25519Keypair, client: SuiClient) { + constructor(keypair: Ed25519Keypair, url: string = DEFAULT_FULLNODE_URL) { this.keypair = keypair; - this.client = client; + this.client = new SuiClient({ + transport: new SuiHTTPTransport({ + url, + WebSocketConstructor: WebSocket as never, + }), + }); + this.registry = TestPackageRegistry.forUrl(url); } address() { @@ -54,6 +87,20 @@ export class TestToolbox { public async getActiveValidators() { return (await this.client.getLatestSuiSystemState()).activeValidators; } + + public async getPackage(path: string) { + return this.registry.getPackage(path, this); + } + + async mintNft(name: string = 'Test NFT') { + const packageId = await this.getPackage(resolve(__dirname, '../data/demo-bear')); + return (tx: Transaction) => { + return tx.moveCall({ + target: `${packageId}::demo_bear::new`, + arguments: [tx.pure.string(name)], + }); + }; + } } export function getClient(url = DEFAULT_FULLNODE_URL): SuiClient { @@ -100,7 +147,7 @@ export async function setupWithFundedAddress( retryIf: () => true, }, ); - return new TestToolbox(keypair, client); + return new TestToolbox(keypair, rpcURL); } export async function publishPackage(packagePath: string, toolbox?: TestToolbox) {