Skip to content

Commit

Permalink
txbuilder arg parser refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC01 committed Dec 9, 2024
1 parent d25ba69 commit 6ddd0c2
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 164 deletions.
6 changes: 5 additions & 1 deletion pysui/sui/sui_txn/transaction_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,12 @@ def transfer_sui(
)
else:
coin_arg = from_coin
elif isinstance(from_coin, bcs.Argument):
else:
coin_arg = from_coin
if isinstance(coin_arg, bcs.Argument):
pass
elif isinstance(coin_arg, bcs.ObjectArg):
coin_arg = self.input_obj_from_objarg(coin_arg)
else:
coin_arg = self.input_obj(*from_coin)
return self.command(
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pylint==3.3.2
pydocstyle==6.3.0
pytest==8.3.4
pytest-asyncio==0.24.0
mypy==1.13.0
types-Deprecated==1.2.15.20241117
build==1.2.1
Expand Down
14 changes: 14 additions & 0 deletions tests/async_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2022 Frank V. Castellucci
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -*- coding: utf-8 -*-

"""Init for package."""
36 changes: 36 additions & 0 deletions tests/async_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright Frank V. Castellucci
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -*- coding: utf-8 -*-

"""Fixtures for testing."""

import pytest
import pytest_asyncio

from pysui import PysuiConfiguration, AsyncGqlClient


# @pytest.fixture(scope="package")
@pytest_asyncio.fixture(scope="package")
def sui_client() -> AsyncGqlClient: # type: ignore
"""Fixture to create a test session wide client pointed to sui-base localnet."""
# sui_base_anynet_start()
# Use for devnet versions
# sui_base_localnet_start()
cfg = PysuiConfiguration(
group_name=PysuiConfiguration.SUI_GQL_RPC_GROUP,
profile_name="devnet",
persist=False,
)
client = AsyncGqlClient(pysui_config=cfg)
# Turn this fixture into a generator
yield client
82 changes: 82 additions & 0 deletions tests/async_tests/test_argprep_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright Frank V. Castellucci
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -*- coding: utf-8 -*-

"""Testing basic client capabilities (no transactions)."""

import os
import pytest
import pytest_asyncio
from pysui import AsyncGqlClient

# import pysui.sui.sui_pgql.pgql_sync_txn as tx
import pysui.sui.sui_pgql.pgql_async_txn as tx
import pysui.sui.sui_pgql.pgql_query as qn


@pytest.mark.asyncio
async def test_split_transfer(sui_client: AsyncGqlClient) -> None:
"""Test splitting and transfers."""

txer = tx.AsyncSuiTransaction(client=sui_client)
scoin = await txer.split_coin(coin=txer.gas, amounts=[1000000000])
await txer.transfer_objects(
transfers=[scoin], recipient=sui_client.config.active_address
)
res = await sui_client.execute_query_node(
with_node=qn.GetCoins(owner=sui_client.config.active_address)
)
coins = res.result_data.data
assert len(coins) > 3
scoin = await txer.split_coin(coin=coins[0], amounts=[1000000000])
await txer.transfer_objects(
transfers=[scoin], recipient=sui_client.config.active_address
)
await txer.split_coin_equal(coin=coins[1], split_count=2)
await txer.transfer_sui(
recipient=sui_client.config.active_address, from_coin=coins[2]
)


@pytest.mark.asyncio
async def test_merge_coin(sui_client: AsyncGqlClient) -> None:
"""Test merging coins."""
txer = tx.AsyncSuiTransaction(client=sui_client)
res = await sui_client.execute_query_node(
with_node=qn.GetCoins(owner=sui_client.config.active_address)
)
coins = res.result_data.data
assert len(coins) > 3
await txer.merge_coins(merge_to=coins[0], merge_from=coins[1:])


@pytest.mark.asyncio
async def test_move_vec(sui_client: AsyncGqlClient) -> None:
"""."""
txer = tx.AsyncSuiTransaction(client=sui_client)
res = await sui_client.execute_query_node(
with_node=qn.GetCoins(owner=sui_client.config.active_address)
)
coins = res.result_data.data
assert len(coins) > 3
coin_ids = [x.coin_object_id for x in coins]
res = await txer.make_move_vector(
items=coin_ids, item_type="0x2::coin::Coin<0x2::sui::SUI"
)


@pytest.mark.asyncio
async def test_publish(sui_client: AsyncGqlClient) -> None:
"""."""
txer = tx.AsyncSuiTransaction(client=sui_client)
cwd = os.getcwd() + "/tests/sui-test"
await txer.publish(project_path=cwd)
2 changes: 1 addition & 1 deletion tests/sui-test/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pysuidance"
version = "0.0.1"
edition = "2024.beta"
edition = "2024"

[dependencies]
Sui = { local = "../../../../suibase/workdirs/active/sui-repo/crates/sui-framework/packages/sui-framework" }
Expand Down
6 changes: 3 additions & 3 deletions tests/sui-test/sources/dancer.move
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ module pysuidance::dancer {
}

/// Override for transfer of tracker
public fun transfer(tracker: Tracker, recipient: address) {
transfer::transfer<Tracker>(tracker, recipient)
}
// public fun transfer(tracker: Tracker, recipient: address) {
// transfer::transfer<Tracker>(tracker, recipient)
// }

/// Get the accumulator length
fun stored_count(self: &Tracker) : u64 {
Expand Down
70 changes: 70 additions & 0 deletions tests/sync_tests/test_argprep_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright Frank V. Castellucci
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -*- coding: utf-8 -*-

"""Testing basic client capabilities (no transactions)."""

import os
from pysui import SyncGqlClient, handle_result
from pysui.sui.sui_types.address import valid_sui_address
import pysui.sui.sui_pgql.pgql_sync_txn as tx
import pysui.sui.sui_pgql.pgql_query as qn
from tests.test_utils import gas_not_in


def test_split_transfer(sui_client: SyncGqlClient) -> None:
"""Test splitting and transfers."""

txer = tx.SuiTransaction(client=sui_client)
scoin = txer.split_coin(coin=txer.gas, amounts=[1000000000])
txer.transfer_objects(transfers=[scoin], recipient=sui_client.config.active_address)
res = sui_client.execute_query_node(
with_node=qn.GetCoins(owner=sui_client.config.active_address)
)
coins = res.result_data.data
assert len(coins) > 3
scoin = txer.split_coin(coin=coins[0], amounts=[1000000000])
txer.transfer_objects(transfers=[scoin], recipient=sui_client.config.active_address)
txer.split_coin_equal(coin=coins[1], split_count=2)
txer.transfer_sui(recipient=sui_client.config.active_address, from_coin=coins[2])


def test_merge_coin(sui_client: SyncGqlClient) -> None:
"""Test merging coins."""
txer = tx.SuiTransaction(client=sui_client)
res = sui_client.execute_query_node(
with_node=qn.GetCoins(owner=sui_client.config.active_address)
)
coins = res.result_data.data
assert len(coins) > 3
txer.merge_coins(merge_to=coins[0], merge_from=coins[1:])


def test_move_vec(sui_client: SyncGqlClient) -> None:
"""."""
txer = tx.SuiTransaction(client=sui_client)
res = sui_client.execute_query_node(
with_node=qn.GetCoins(owner=sui_client.config.active_address)
)
coins = res.result_data.data
assert len(coins) > 3
coin_ids = [x.coin_object_id for x in coins]
res = txer.make_move_vector(
items=coin_ids, item_type="0x2::coin::Coin<0x2::sui::SUI"
)


def test_publish(sui_client: SyncGqlClient) -> None:
"""."""
txer = tx.SuiTransaction(client=sui_client)
cwd = os.getcwd() + "/tests/sui-test"
txer.publish(project_path=cwd)
Loading

0 comments on commit 6ddd0c2

Please sign in to comment.