-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
212 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.