From 570584a03508d808c4b37633206bce2b6c805f80 Mon Sep 17 00:00:00 2001 From: luc10921 Date: Thu, 23 May 2024 11:31:27 -0300 Subject: [PATCH] CU-86dthh0nm - Update NeoToken native contract --- .../native/neo_contract_methods/__init__.py | 4 +++ .../getcommitteeaddressmethod.py | 13 ++++++++++ .../getregisterpricemethod.py | 13 ++++++++++ .../internal/model/builtin/native/neoclass.py | 14 +++++----- boa3/sc/contracts/neotoken.py | 26 +++++++++++++++++++ .../native_test/neo/GetCommitteeAddress.py | 8 ++++++ .../native_test/neo/GetRegisterPrice.py | 7 +++++ .../compiler_tests/test_native/test_neo.py | 22 ++++++++++++++++ 8 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 boa3/internal/model/builtin/native/neo_contract_methods/getcommitteeaddressmethod.py create mode 100644 boa3/internal/model/builtin/native/neo_contract_methods/getregisterpricemethod.py create mode 100644 boa3_test/test_sc/native_test/neo/GetCommitteeAddress.py create mode 100644 boa3_test/test_sc/native_test/neo/GetRegisterPrice.py diff --git a/boa3/internal/model/builtin/native/neo_contract_methods/__init__.py b/boa3/internal/model/builtin/native/neo_contract_methods/__init__.py index 23e375746..de36eb1d0 100644 --- a/boa3/internal/model/builtin/native/neo_contract_methods/__init__.py +++ b/boa3/internal/model/builtin/native/neo_contract_methods/__init__.py @@ -3,8 +3,10 @@ 'GetCandidatesMethod', 'GetCandidateVoteMethod', 'GetCommitteeMethod', + 'GetCommitteeAddressMethod', 'GetGasPerBlockMethod', 'GetNextBlockValidatorsMethod', + 'GetRegisterPriceMethod', 'RegisterCandidateMethod', 'UnclaimedGasMethod', 'UnregisterCandidateMethod', @@ -17,8 +19,10 @@ from boa3.internal.model.builtin.native.neo_contract_methods.getcandidatesmethod import GetCandidatesMethod from boa3.internal.model.builtin.native.neo_contract_methods.getcandidatevotemethod import GetCandidateVoteMethod from boa3.internal.model.builtin.native.neo_contract_methods.getcommitteemethod import GetCommitteeMethod +from boa3.internal.model.builtin.native.neo_contract_methods.getcommitteeaddressmethod import GetCommitteeAddressMethod from boa3.internal.model.builtin.native.neo_contract_methods.getgasperblockmethod import GetGasPerBlockMethod from boa3.internal.model.builtin.native.neo_contract_methods.getnextblockvalidators import GetNextBlockValidatorsMethod +from boa3.internal.model.builtin.native.neo_contract_methods.getregisterpricemethod import GetRegisterPriceMethod from boa3.internal.model.builtin.native.neo_contract_methods.registercandidatemethod import RegisterCandidateMethod from boa3.internal.model.builtin.native.neo_contract_methods.unclaimedgasmethod import UnclaimedGasMethod from boa3.internal.model.builtin.native.neo_contract_methods.unregistercandidatemethod import UnregisterCandidateMethod diff --git a/boa3/internal/model/builtin/native/neo_contract_methods/getcommitteeaddressmethod.py b/boa3/internal/model/builtin/native/neo_contract_methods/getcommitteeaddressmethod.py new file mode 100644 index 000000000..e64bd12e7 --- /dev/null +++ b/boa3/internal/model/builtin/native/neo_contract_methods/getcommitteeaddressmethod.py @@ -0,0 +1,13 @@ +from boa3.internal.model.builtin.interop.nativecontract import NeoContractMethod +from boa3.internal.model.variable import Variable + + +class GetCommitteeAddressMethod(NeoContractMethod): + + def __init__(self): + from boa3.internal.model.type.collection.sequence.uint160type import UInt160Type + + identifier = 'get_committee_address' + native_identifier = 'getCommitteeAddress' + args: dict[str, Variable] = {} + super().__init__(identifier, native_identifier, args, return_type=UInt160Type.build()) diff --git a/boa3/internal/model/builtin/native/neo_contract_methods/getregisterpricemethod.py b/boa3/internal/model/builtin/native/neo_contract_methods/getregisterpricemethod.py new file mode 100644 index 000000000..2a0a5e21c --- /dev/null +++ b/boa3/internal/model/builtin/native/neo_contract_methods/getregisterpricemethod.py @@ -0,0 +1,13 @@ +from boa3.internal.model.builtin.interop.nativecontract import NeoContractMethod +from boa3.internal.model.variable import Variable + + +class GetRegisterPriceMethod(NeoContractMethod): + + def __init__(self): + from boa3.internal.model.type.type import Type + + identifier = 'get_register_price' + native_identifier = 'getRegisterPrice' + args: dict[str, Variable] = {} + super().__init__(identifier, native_identifier, args, return_type=Type.int) diff --git a/boa3/internal/model/builtin/native/neoclass.py b/boa3/internal/model/builtin/native/neoclass.py index c4eebbaa8..adaa58323 100644 --- a/boa3/internal/model/builtin/native/neoclass.py +++ b/boa3/internal/model/builtin/native/neoclass.py @@ -19,12 +19,12 @@ def class_methods(self) -> dict[str, Method]: # avoid recursive import from boa3.internal.model.builtin.native.nep17_methods import (BalanceOfMethod, DecimalsMethod, SymbolMethod, TotalSupplyMethod, TransferMethod) - from boa3.internal.model.builtin.native.neo_contract_methods import (GetAccountStateMethod, GetAllCandidatesMethod, - GetCandidatesMethod, GetCandidateVoteMethod, - GetCommitteeMethod, GetGasPerBlockMethod, - GetNextBlockValidatorsMethod, - RegisterCandidateMethod, UnclaimedGasMethod, - UnregisterCandidateMethod, UnVoteMethod, VoteMethod) + from boa3.internal.model.builtin.native.neo_contract_methods import ( + GetAccountStateMethod, GetAllCandidatesMethod, GetCandidatesMethod, GetCandidateVoteMethod, + GetCommitteeMethod, GetGasPerBlockMethod, GetNextBlockValidatorsMethod, GetRegisterPriceMethod, + RegisterCandidateMethod, UnclaimedGasMethod, UnregisterCandidateMethod, UnVoteMethod, VoteMethod, + GetCommitteeAddressMethod + ) from boa3.internal.model.builtin.contract import NeoAccountStateType if len(self._class_methods) == 0: @@ -40,8 +40,10 @@ def class_methods(self) -> dict[str, Method]: 'get_candidates': GetCandidatesMethod(), 'get_candidate_vote': GetCandidateVoteMethod(), 'get_committee': GetCommitteeMethod(), + 'get_committee_address': GetCommitteeAddressMethod(), 'get_gas_per_block': GetGasPerBlockMethod(), 'get_next_block_validators': GetNextBlockValidatorsMethod(), + 'get_register_price': GetRegisterPriceMethod(), 'register_candidate': RegisterCandidateMethod(), 'unclaimed_gas': UnclaimedGasMethod(), 'unregister_candidate': UnregisterCandidateMethod(), diff --git a/boa3/sc/contracts/neotoken.py b/boa3/sc/contracts/neotoken.py index dd7d0e0df..fbc8012d2 100644 --- a/boa3/sc/contracts/neotoken.py +++ b/boa3/sc/contracts/neotoken.py @@ -259,6 +259,32 @@ def get_committee(cls) -> list[ECPoint]: """ pass + @classmethod + def get_committee_address(cls) -> UInt160: + """ + Gets the address of the committee. + + >>> NeoToken.get_committee_address() + UInt160(0x9273d3c792bce5eab4daac1c3ffdc1e83c4237f7) + + :return: the address of the committee + :rtype: UInt160 + """ + pass + + @classmethod + def get_register_price(cls) -> int: + """ + Gets the fees to be paid to register as a candidate. + + >>> NeoToken.get_register_price() + 100000000000 + + :return: the amount of the fees + :rtype: int + """ + pass + @classmethod def get_next_block_validators(cls) -> list[ECPoint]: """ diff --git a/boa3_test/test_sc/native_test/neo/GetCommitteeAddress.py b/boa3_test/test_sc/native_test/neo/GetCommitteeAddress.py new file mode 100644 index 000000000..081740c4d --- /dev/null +++ b/boa3_test/test_sc/native_test/neo/GetCommitteeAddress.py @@ -0,0 +1,8 @@ +from boa3.sc.compiletime import public +from boa3.sc.contracts import NeoToken +from boa3.sc.types import UInt160 + + +@public +def main() -> UInt160: + return NeoToken.get_committee_address() diff --git a/boa3_test/test_sc/native_test/neo/GetRegisterPrice.py b/boa3_test/test_sc/native_test/neo/GetRegisterPrice.py new file mode 100644 index 000000000..de196e550 --- /dev/null +++ b/boa3_test/test_sc/native_test/neo/GetRegisterPrice.py @@ -0,0 +1,7 @@ +from boa3.sc.compiletime import public +from boa3.sc.contracts import NeoToken + + +@public +def main() -> int: + return NeoToken.get_register_price() diff --git a/boa3_test/tests/compiler_tests/test_native/test_neo.py b/boa3_test/tests/compiler_tests/test_native/test_neo.py index e3c44b4e3..f2da8276d 100644 --- a/boa3_test/tests/compiler_tests/test_native/test_neo.py +++ b/boa3_test/tests/compiler_tests/test_native/test_neo.py @@ -11,6 +11,7 @@ from boa3.internal import constants from boa3.internal.exception import CompilerError, CompilerWarning +from boa3.internal.neo.vm.opcode.Opcode import Opcode from boa3_test.tests import annotation, boatestcase @@ -75,6 +76,11 @@ async def get_gas_per_block(cls) -> int: async with noderpc.NeoRpcClient(cls.node.facade.rpc_host): return await cls.node.facade.test_invoke(NeoToken().get_gas_per_block()) + @classmethod + async def get_register_price(cls) -> int: + async with noderpc.NeoRpcClient(cls.node.facade.rpc_host): + return await cls.node.facade.test_invoke(NeoToken().candidate_registration_price()) + async def test_get_hash(self): await self.set_up_contract('GetHash.py') @@ -579,3 +585,19 @@ async def test_get_account_state(self): self.assertIsNone(result[2]) self.assertGreaterEqual(result[3], 0) self.assertRegex(str(context.exception), "item is not of type 'StackItemType.ARRAY' but of type 'StackItemType.STRUCT'") + + async def test_get_committee_address(self): + expected_output = ( + Opcode.CALLT + b'\x00\x00' + + Opcode.RET + ) + + output, _ = self.assertCompile('GetCommitteeAddress.py') + self.assertEqual(expected_output, output) + + async def test_get_register_price(self): + await self.set_up_contract('GetRegisterPrice.py') + + register_price = await self.get_register_price() + result, _ = await self.call('main', [], return_type=int) + self.assertEqual(register_price, result)