multiversx / mx-sdk-py

The MultiversX Python SDK.
MIT License
5 stars 0 forks source link

Feat: codecs & ABI #52

Closed andreibancioiu closed 1 month ago

andreibancioiu commented 1 month ago

Based on this incubator branch: https://github.com/multiversx/mx-sdk-py/pull/32.

As seen here (Go):

Reference:

Examples (transactions)

abi = Abi.load(testdata / "multisig-full.abi.json")
config = TransactionsFactoryConfig("D")
factory = SmartContractTransactionsFactory(config, abi)

# All arguments untyped (multisig propose batch)
transaction = factory.create_transaction_for_execute(
    ...
    function="proposeBatch",
    arguments=[
        [
            {
                "__discriminant__": 5,
                "0": {
                    "to": alice,
                    "egld_amount": 1000000000000000000,
                    "endpoint_name": "example",
                    "arguments": [
                        bytes([0x03, 0x42]),
                        bytes([0x07, 0x43])
                    ],
                    "opt_gas_limit": 15_000_000
                }
            }
        ]
    ]
)

# All arguments typed (multisig propose batch)
transaction= factory.create_transaction_for_execute(
    ...
    function="proposeBatch",
    arguments=[
        VariadicValues(
        [
            EnumValue(
                discriminant=5,
                fields=[
                    Field("0", StructValue([
                        Field("to", AddressValue.from_address(alice)),
                        Field("egld_amount", BigUIntValue(1000000000000000000)),
                        Field("opt_gas_limit", OptionValue(U64Value(15_000_000))),
                        Field("endpoint_name", BytesValue(b"example")),
                        Field("arguments", ListValue([
                            BytesValue(bytes([0x03, 0x42])),
                            BytesValue(bytes([0x07, 0x43])),
                        ])),
                    ])),
                ],
            )
        ])
    ]
)

Examples (queries)

abi = Abi.load(self.testdata / "lottery-esdt.abi.json")
query_runner = QueryRunnerAdapter(ApiNetworkProvider("https://devnet-api.multiversx.com"))
controller = SmartContractQueriesController(query_runner, abi)

[lottery_info] = controller.query(
    ...
    function="getLotteryInfo",
    arguments=["myLottery"]
)

assert lottery_info.token_identifier == "lucky-token"
assert lottery_info.ticket_price == 1
assert lottery_info.tickets_left == 0
assert lottery_info.deadline == 0x000000005fc2b9db
assert lottery_info.max_entries_per_user == 0xffffffff
assert lottery_info.prize_distribution == bytes([0x64])
assert lottery_info.prize_pool == 94720000000000000000000
github-actions[bot] commented 1 month ago

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  multiversx_sdk/abi
  abi.py 77, 97, 144, 169, 177, 189, 195, 197, 199, 203
  abi_definition.py 40, 49, 97, 113, 129, 159, 184, 207, 227, 248, 255-256, 260-262, 268, 276-278, 282, 289
  address_value.py 14, 30, 37-38, 53
  bigint_value.py 11, 14-16, 19-20, 23-25, 28, 31-38, 41, 44, 47, 50, 53
  biguint_value.py 35
  bool_value.py 13-17, 26-27, 30-38, 41-47, 53, 56, 59
  bytes_value.py 27, 39
  codec.py 12-14, 22-27
  enum_value.py 33, 39, 49-54, 62, 80, 87, 100
  fields.py 26-27, 34-35
  interface.py 7, 10, 16, 19, 22, 25
  list_value.py 21, 31-35, 43, 66
  option_value.py 16-17, 23-27, 31, 37-38, 44, 47-61, 84
  optional_value.py 13-14, 20-21, 27
  parts.py 29, 34, 49, 58
  serializer.py 19, 36, 58, 92, 98, 102
  shared.py 21, 25
  small_int_values.py 21, 52-53, 56-57, 60-67, 70-71, 74-80, 83, 86, 89, 121, 126, 129, 134, 137, 142, 145, 150, 153
  string_value.py 17, 42
  struct_value.py 21, 38-39
  tuple_value.py 13-17, 20, 23-27, 30-31, 37, 51
  type_formula_parser.py 27, 33, 35, 45, 82, 95
  multiversx_sdk/core
  smart_contract_queries_controller.py 20, 23, 85
  smart_contract_query.py 21, 40-43
  multiversx_sdk/core/transactions_factories
  smart_contract_transactions_factory.py 32, 35, 38
Project Total  

The report is truncated to 25 files out of 35. To see the full report, please visit the workflow summary page.

This report was generated by python-coverage-comment-action