-
Notifications
You must be signed in to change notification settings - Fork 26
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
6 changed files
with
190 additions
and
2 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
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,140 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2023 RBB S.r.l | ||
# Copyright (c) 2017-2021 The Bitcoin Core developers | ||
# [email protected] | ||
# SPDX-License-Identifier: MIT | ||
# Licensed under the MIT License; | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE | ||
# | ||
# 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. | ||
"""Wallet tokens change metadata uri test | ||
Check that: | ||
* We can create a new wallet, | ||
* get an address | ||
* send coins to the wallet's address | ||
* sync the wallet with the node | ||
* check balance | ||
* issue new token | ||
* check metadata uri | ||
* change metadata uri | ||
* check that metadata uri is changed | ||
""" | ||
|
||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.mintlayer import (make_tx, reward_input, ATOMS_PER_COIN) | ||
from test_framework.util import assert_in, assert_equal | ||
from test_framework.mintlayer import block_input_data_obj | ||
from test_framework.wallet_cli_controller import WalletCliController | ||
|
||
import asyncio | ||
import sys | ||
import random | ||
import string | ||
|
||
class WalletTokens(BitcoinTestFramework): | ||
|
||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
self.num_nodes = 1 | ||
self.extra_args = [[ | ||
"--blockprod-min-peers-to-produce-blocks=0", | ||
]] | ||
|
||
def setup_network(self): | ||
self.setup_nodes() | ||
self.sync_all(self.nodes[0:1]) | ||
|
||
def generate_block(self): | ||
node = self.nodes[0] | ||
|
||
block_input_data = { "PoW": { "reward_destination": "AnyoneCanSpend" } } | ||
block_input_data = block_input_data_obj.encode(block_input_data).to_hex()[2:] | ||
|
||
# create a new block, taking transactions from mempool | ||
block = node.blockprod_generate_block(block_input_data, [], [], "FillSpaceFromMempool") | ||
node.chainstate_submit_block(block) | ||
block_id = node.chainstate_best_block_id() | ||
|
||
# Wait for mempool to sync | ||
self.wait_until(lambda: node.mempool_local_best_block_id() == block_id, timeout = 5) | ||
|
||
return block_id | ||
|
||
def run_test(self): | ||
if 'win32' in sys.platform: | ||
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy()) | ||
asyncio.run(self.async_test()) | ||
|
||
async def async_test(self): | ||
node = self.nodes[0] | ||
|
||
# new wallet | ||
async with WalletCliController(node, self.config, self.log) as wallet: | ||
await wallet.create_wallet() | ||
|
||
# check it is on genesis | ||
assert_equal('0', await wallet.get_best_block_height()) | ||
|
||
# new address | ||
pub_key_bytes = await wallet.new_public_key() | ||
assert_equal(len(pub_key_bytes), 33) | ||
|
||
# Get chain tip | ||
tip_id = node.chainstate_best_block_id() | ||
self.log.debug(f'Tip: {tip_id}') | ||
|
||
# Submit a valid transaction | ||
output = { | ||
'Transfer': [ { 'Coin': 1001 * ATOMS_PER_COIN }, { 'PublicKey': {'key': {'Secp256k1Schnorr' : {'pubkey_data': pub_key_bytes}}} } ], | ||
} | ||
encoded_tx, tx_id = make_tx([reward_input(tip_id)], [output], 0) | ||
|
||
node.mempool_submit_transaction(encoded_tx, {}) | ||
assert node.mempool_contains_tx(tx_id) | ||
|
||
block_id = self.generate_block() # Block 1 | ||
assert not node.mempool_contains_tx(tx_id) | ||
|
||
# sync the wallet | ||
assert_in("Success", await wallet.sync()) | ||
|
||
# check wallet best block if it is synced | ||
assert_equal(await wallet.get_best_block_height(), '1') | ||
assert_equal(await wallet.get_best_block(), block_id) | ||
assert_in("Coins amount: 1001", await wallet.get_balance()) | ||
|
||
# issue a valid token | ||
address = await wallet.new_address() | ||
metadata_uri = "http://uri" | ||
token_id, err = await wallet.issue_new_token("XXX", 2, metadata_uri, address, token_supply='lockable') | ||
assert token_id is not None | ||
assert err is None | ||
self.log.info(f"new token id: {token_id}") | ||
|
||
self.generate_block() | ||
assert_in("Success", await wallet.sync()) | ||
|
||
token_info = node.chainstate_token_info(token_id) | ||
assert_equal(metadata_uri, token_info['content']['metadata_uri']['text']); | ||
|
||
new_metadata_uri = bytes([random.randint(0, 255) for _ in range(random.randint(1, 128))]).hex() | ||
assert_in("The transaction was submitted successfully", await wallet.change_token_metadata_uri(token_id, new_metadata_uri)) | ||
|
||
self.generate_block() | ||
assert_in("Success", await wallet.sync()) | ||
|
||
token_info = node.chainstate_token_info(token_id) | ||
print(token_info) | ||
assert_equal(new_metadata_uri, token_info['content']['metadata_uri']['hex']); | ||
assert token_info['content']['metadata_uri']['text'] is not metadata_uri | ||
|
||
if __name__ == '__main__': | ||
WalletTokens().main() |
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,34 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2023 RBB S.r.l | ||
# Copyright (c) 2017-2021 The Bitcoin Core developers | ||
# [email protected] | ||
# SPDX-License-Identifier: MIT | ||
# Licensed under the MIT License; | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE | ||
# | ||
# 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. | ||
|
||
"""Wallet tokens change metadta uri test""" | ||
|
||
from wallet_tokens_change_metadata_uri import WalletTokens | ||
from test_framework.wallet_rpc_controller import WalletRpcController | ||
|
||
|
||
class WalletTokensRpc(WalletTokens): | ||
def set_test_params(self): | ||
super().set_test_params() | ||
self.wallet_controller = WalletRpcController | ||
|
||
def run_test(self): | ||
super().run_test() | ||
|
||
|
||
if __name__ == '__main__': | ||
WalletTokensRpc().main() |
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