def test_policy_before_future( self, cluster: clusterlib.ClusterLib, issuers_addrs: List[clusterlib.AddressRecord]): """Test that it's NOT possible to mint tokens. The "before" slot is in the future and the given range is invalid. """ temp_template = helpers.get_func_name() rand = clusterlib.get_rand_str(4) amount = 5 token_mint_addr = issuers_addrs[0] payment_vkey_files = [p.vkey_file for p in issuers_addrs] before_slot = cluster.get_slot_no() + 10_000 # create multisig script multisig_script = cluster.build_multisig_script( script_name=temp_template, script_type_arg=clusterlib.MultiSigTypeArgs.ALL, payment_vkey_files=payment_vkey_files[1:], slot=before_slot, slot_type_arg=clusterlib.MultiSlotTypeArgs.BEFORE, ) policyid = cluster.get_policyid(multisig_script) tokens_to_mint = [] for tnum in range(5): asset_name = f"couttscoin{rand}{tnum}" token = f"{policyid}.{asset_name}" assert not cluster.get_utxo(token_mint_addr.address, coins=[ token ]), "The token already exists" tokens_to_mint.append( clusterlib_utils.TokenRecord( token=token, asset_name=asset_name, amount=amount, issuers_addrs=issuers_addrs, token_mint_addr=token_mint_addr, script=multisig_script, )) # token minting - invalid range, slot is in the future with pytest.raises(clusterlib.CLIError) as excinfo: _mint_or_burn_witness( cluster_obj=cluster, new_tokens=tokens_to_mint, temp_template=f"{temp_template}_mint", invalid_before=1, invalid_hereafter=before_slot + 1, ) assert "ScriptWitnessNotValidatingUTXOW" in str(excinfo.value) for t in tokens_to_mint: token_utxo = cluster.get_utxo(token_mint_addr.address, coins=[t.token]) assert not token_utxo, "The token was minted unexpectedly"
def test_long_name( self, cluster: clusterlib.ClusterLib, issuers_addrs: List[clusterlib.AddressRecord], simple_script_policyid: Tuple[Path, str], asset_name: str, ): """Try to create token with asset name that is longer than allowed. The name can also contain characters that are not allowed. Expect failure. """ temp_template = "test_long_name" script, policyid = simple_script_policyid token = f"{policyid}.{asset_name}" token_mint_addr = issuers_addrs[0] issuer_addr = issuers_addrs[1] amount = 20_000_000 token_mint = clusterlib_utils.TokenRecord( token=token, asset_name=asset_name, amount=amount, issuers_addrs=[issuer_addr], token_mint_addr=token_mint_addr, script=script, ) with pytest.raises(clusterlib.CLIError) as excinfo: self._mint_tx( cluster_obj=cluster, new_tokens=[token_mint], temp_template=f"{temp_template}_mint", ) exc_val = str(excinfo.value) assert ("name exceeds 32 bytes" in exc_val or "expecting letter or digit, white space" in exc_val or "expecting alphanumeric asset name" in exc_val)
def test_valid_policy_before( self, cluster: clusterlib.ClusterLib, issuers_addrs: List[clusterlib.AddressRecord]): """Test minting and burning tokens before given slot.""" expected_fee = 351093 temp_template = helpers.get_func_name() rand = clusterlib.get_rand_str(4) amount = 5 token_mint_addr = issuers_addrs[0] payment_vkey_files = [p.vkey_file for p in issuers_addrs] before_slot = cluster.get_slot_no() + 10_000 # create multisig script multisig_script = cluster.build_multisig_script( script_name=temp_template, script_type_arg=clusterlib.MultiSigTypeArgs.ALL, payment_vkey_files=payment_vkey_files[1:], slot=before_slot, slot_type_arg=clusterlib.MultiSlotTypeArgs.BEFORE, ) policyid = cluster.get_policyid(multisig_script) tokens_to_mint = [] for tnum in range(5): asset_name = f"couttscoin{rand}{tnum}" token = f"{policyid}.{asset_name}" assert not cluster.get_utxo(token_mint_addr.address, coins=[ token ]), "The token already exists" tokens_to_mint.append( clusterlib_utils.TokenRecord( token=token, asset_name=asset_name, amount=amount, issuers_addrs=issuers_addrs, token_mint_addr=token_mint_addr, script=multisig_script, )) # token minting tx_out_mint = _mint_or_burn_witness( cluster_obj=cluster, new_tokens=tokens_to_mint, temp_template=f"{temp_template}_mint", invalid_before=100, invalid_hereafter=cluster.get_slot_no() + 1000, ) for t in tokens_to_mint: token_utxo = cluster.get_utxo(token_mint_addr.address, coins=[t.token]) assert token_utxo and token_utxo[ 0].amount == amount, "The token was not minted" # token burning tokens_to_burn = [t._replace(amount=-amount) for t in tokens_to_mint] tx_out_burn = _mint_or_burn_witness( cluster_obj=cluster, new_tokens=tokens_to_burn, temp_template=f"{temp_template}_burn", invalid_before=100, invalid_hereafter=cluster.get_slot_no() + 1000, ) for t in tokens_to_burn: token_utxo = cluster.get_utxo(token_mint_addr.address, coins=[t.token]) assert not token_utxo, "The token was not burnt" # check expected fees assert helpers.is_in_interval( tx_out_mint.fee, expected_fee, frac=0.15) and helpers.is_in_interval( tx_out_burn.fee, expected_fee, frac=0.15), "TX fee doesn't fit the expected interval"
def test_minting_and_partial_burning( self, cluster: clusterlib.ClusterLib, issuers_addrs: List[clusterlib.AddressRecord]): """Test minting and partial burning of tokens.""" expected_fee = 201141 temp_template = helpers.get_func_name() asset_name = f"couttscoin{clusterlib.get_rand_str(4)}" amount = 50 payment_vkey_files = [p.vkey_file for p in issuers_addrs] token_mint_addr = issuers_addrs[0] # create multisig script multisig_script = cluster.build_multisig_script( script_name=temp_template, script_type_arg=clusterlib.MultiSigTypeArgs.ALL, payment_vkey_files=payment_vkey_files[1:], ) policyid = cluster.get_policyid(multisig_script) token = f"{policyid}.{asset_name}" assert not cluster.get_utxo(token_mint_addr.address, coins=[token]), "The token already exists" token_mint = clusterlib_utils.TokenRecord( token=token, asset_name=asset_name, amount=amount, issuers_addrs=issuers_addrs, token_mint_addr=token_mint_addr, script=multisig_script, ) # token minting tx_out_mint = _mint_or_burn_witness( cluster_obj=cluster, new_tokens=[token_mint], temp_template=f"{temp_template}_mint", ) token_utxo = cluster.get_utxo(token_mint_addr.address, coins=[token]) assert token_utxo and token_utxo[ 0].amount == amount, "The token was not minted" # token burning burn_amount = amount - 10 token_burn = token_mint._replace(amount=-burn_amount) _mint_or_burn_witness( cluster_obj=cluster, new_tokens=[token_burn], temp_template=f"{temp_template}_burn", ) token_utxo = cluster.get_utxo(token_mint_addr.address, coins=[token]) assert (token_utxo and token_utxo[0].amount == amount - burn_amount), "The token was not burned" # burn the rest of tokens final_burn = token_mint._replace(amount=-10) _mint_or_burn_witness( cluster_obj=cluster, new_tokens=[final_burn], temp_template=f"{temp_template}_burn", ) # check expected fee assert helpers.is_in_interval( tx_out_mint.fee, expected_fee, frac=0.15), "TX fee doesn't fit the expected interval"
def test_multi_minting_and_burning_sign( self, cluster: clusterlib.ClusterLib, issuers_addrs: List[clusterlib.AddressRecord], simple_script_policyid: Tuple[Path, str], tokens_db: Tuple[int, int], ): """Test minting and burning multiple different tokens, sign the TX using skeys.""" temp_template = helpers.get_func_name() rand = clusterlib.get_rand_str(8) amount = 5 tokens_num, expected_fee = tokens_db token_mint_addr = issuers_addrs[0] issuer_addr = issuers_addrs[1] script, policyid = simple_script_policyid tokens_to_mint = [] for tnum in range(tokens_num): asset_name = f"couttscoin{rand}{tnum}" token = f"{policyid}.{asset_name}" tokens_to_mint.append( clusterlib_utils.TokenRecord( token=token, asset_name=asset_name, amount=amount, issuers_addrs=[issuer_addr], token_mint_addr=token_mint_addr, script=script, )) # token minting minting_args = { "cluster_obj": cluster, "new_tokens": tokens_to_mint, "temp_template": f"{temp_template}_mint", } if tokens_num >= 500: with pytest.raises(clusterlib.CLIError) as excinfo: clusterlib_utils.mint_or_burn_sign( **minting_args) # type: ignore if tokens_num >= 1000: assert "(UtxoFailure (MaxTxSizeUTxO" in str(excinfo.value) else: assert "(UtxoFailure (OutputTooBigUTxO" in str(excinfo.value) return tx_out_mint = clusterlib_utils.mint_or_burn_sign( **minting_args) # type: ignore for t in tokens_to_mint: token_utxo = cluster.get_utxo(token_mint_addr.address, coins=[t.token]) assert token_utxo and token_utxo[ 0].amount == amount, "The token was not minted" # token burning tokens_to_burn = [t._replace(amount=-amount) for t in tokens_to_mint] tx_out_burn = clusterlib_utils.mint_or_burn_sign( cluster_obj=cluster, new_tokens=tokens_to_burn, temp_template=f"{temp_template}_burn", ) for t in tokens_to_burn: token_utxo = cluster.get_utxo(token_mint_addr.address, coins=[t.token]) assert not token_utxo, "The token was not burnt" # check expected fees assert helpers.is_in_interval( tx_out_mint.fee, expected_fee, frac=0.15) and helpers.is_in_interval( tx_out_burn.fee, expected_fee, frac=0.15), "TX fee doesn't fit the expected interval"
def test_minting_and_burning_sign( self, cluster: clusterlib.ClusterLib, issuers_addrs: List[clusterlib.AddressRecord]): """Test minting and burning of tokens, sign the transaction using skeys.""" expected_fee = 188821 temp_template = helpers.get_func_name() asset_name = f"couttscoin{clusterlib.get_rand_str(4)}" amount = 5 token_mint_addr = issuers_addrs[0] issuer_addr = issuers_addrs[1] # create simple script keyhash = cluster.get_payment_vkey_hash(issuer_addr.vkey_file) script_content = {"keyHash": keyhash, "type": "sig"} script = Path(f"{temp_template}.script") with open(f"{temp_template}.script", "w") as out_json: json.dump(script_content, out_json) policyid = cluster.get_policyid(script) token = f"{policyid}.{asset_name}" assert not cluster.get_utxo(token_mint_addr.address, coins=[token]), "The token already exists" token_mint = clusterlib_utils.TokenRecord( token=token, asset_name=asset_name, amount=amount, issuers_addrs=[issuer_addr], token_mint_addr=token_mint_addr, script=script, ) # token minting tx_out_mint = clusterlib_utils.mint_or_burn_sign( cluster_obj=cluster, new_tokens=[token_mint], temp_template=f"{temp_template}_mint", ) token_utxo = cluster.get_utxo(token_mint_addr.address, coins=[token]) assert token_utxo and token_utxo[ 0].amount == amount, "The token was not minted" # token burning token_burn = token_mint._replace(amount=-amount) tx_out_burn = clusterlib_utils.mint_or_burn_sign( cluster_obj=cluster, new_tokens=[token_burn], temp_template=f"{temp_template}_burn", ) token_utxo = cluster.get_utxo(token_mint_addr.address, coins=[token]) assert not token_utxo, "The token was not burnt" # check expected fees assert helpers.is_in_interval( tx_out_mint.fee, expected_fee, frac=0.15) and helpers.is_in_interval( tx_out_burn.fee, expected_fee, frac=0.15), "TX fee doesn't fit the expected interval"