Skip to content

Commit c46a7fa

Browse files
authored
Merge pull request #1911 from mintlayer/fix/api-server-burn-output
fix api server Burn output and tx inspect freezable
2 parents 45a8920 + 5c332fe commit c46a7fa

17 files changed

+75
-38
lines changed

api-server/stack-test-suite/tests/v2/transaction.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,14 +529,14 @@ async fn mint_tokens(#[case] seed: Seed) {
529529
TxInput::from_utxo(tx1_id.into(), 0),
530530
empty_witness(&mut rng),
531531
)
532+
.add_output(TxOutput::Burn(OutputValue::TokenV1(
533+
token_id,
534+
amount_to_mint,
535+
)))
532536
.add_output(TxOutput::Transfer(
533537
OutputValue::Coin(coins_after_mint),
534538
Destination::AnyoneCanSpend,
535539
))
536-
.add_output(TxOutput::Transfer(
537-
OutputValue::TokenV1(token_id, amount_to_mint),
538-
Destination::AnyoneCanSpend,
539-
))
540540
.build();
541541

542542
let tx2_id = tx2.transaction().get_id();
@@ -615,5 +615,10 @@ async fn mint_tokens(#[case] seed: Seed) {
615615
mint_amount
616616
);
617617

618+
let outputs = body.get("outputs").unwrap().as_array().unwrap();
619+
assert_eq!(outputs.len(), 2);
620+
let burn_out = outputs.first().unwrap().as_object().unwrap();
621+
assert_eq!(burn_out.get("type").unwrap().as_str().unwrap(), "Burn",);
622+
618623
task.abort();
619624
}

api-server/web-server/src/api/json_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub fn txoutput_to_json(
126126
}
127127
TxOutput::Burn(value) => {
128128
json!({
129-
"type": "LockThenTransfer",
129+
"type": "Burn",
130130
"value": outputvalue_to_json(value, chain_config, token_decimals),
131131
})
132132
}

common/src/chain/transaction/output/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ impl TextSummary for TxOutput {
237237
TokenTotalSupply::Unlimited => "Unlimited".to_string(),
238238
};
239239
let fmt_tkn_frzble = |f: &IsTokenFreezable| match f {
240-
IsTokenFreezable::No => "Yes".to_string(),
241-
IsTokenFreezable::Yes => "No".to_string(),
240+
IsTokenFreezable::No => "No".to_string(),
241+
IsTokenFreezable::Yes => "Yes".to_string(),
242242
};
243243
let fmt_tkn_iss = |iss: &TokenIssuance| {
244244
match iss {

test/functional/test_framework/wallet_cli_controller.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,15 @@ async def issue_new_token(self,
329329
metadata_uri: str,
330330
destination_address: str,
331331
token_supply: str = 'unlimited',
332-
is_freezable: str = 'freezable') -> Tuple[Optional[str], Optional[str]]:
332+
is_freezable: str = 'freezable') -> Tuple[Optional[str], Optional[str], Optional[str]]:
333333
output = await self._write_command(f'token-issue-new "{token_ticker}" "{number_of_decimals}" "{metadata_uri}" {destination_address} {token_supply} {is_freezable}\n')
334334
if output.startswith("A new token has been issued with ID"):
335-
begin = output.find(':') + 2
336-
end = output.find(' ', begin)
337-
return output[begin:end], None
335+
token_id_begin = output.find(':') + 2
336+
token_id_end = output.find(' ', token_id_begin)
337+
tx_id_begin = output.find(':', token_id_end) + 2
338+
return output[token_id_begin:token_id_end], output[tx_id_begin:], None
338339

339-
return None, output
340+
return None, None, output
340341

341342
async def mint_tokens(self, token_id: str, address: str, amount: int) -> str:
342343
return await self._write_command(f"token-mint {token_id} {address} {amount}\n")

test/functional/test_framework/wallet_rpc_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ async def issue_new_token(self,
291291
])
292292

293293
if 'result' in result:
294-
return result['result']['token_id'], None
294+
return result['result']['token_id'], result['result']['tx_id'], None
295295
else:
296-
return None, result['error']
296+
return None, None, result['error']
297297

298298
async def mint_tokens(self, token_id: str, address: str, amount: int) -> str:
299299
return self._write_command("token_mint", [self.account, token_id, address, {'decimal': str(amount)}, {'in_top_x_mb': 5}])['result']

test/functional/wallet_conflict.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ async def async_test(self):
119119
assert_in(f"Coins amount: {coins_to_send * 2 + token_fee}", await wallet.get_balance())
120120

121121
address = await wallet.new_address()
122-
token_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", address)
122+
token_id, tx_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", address)
123123
assert token_id is not None
124+
assert tx_id is not None
124125
assert err is None
125126

126127
self.generate_block()

test/functional/wallet_htlc_refund.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async def async_test(self):
134134
# issue a valid token
135135
token_ticker = "XXXX"
136136
token_number_of_decimals = 2
137-
token_id, _ = (await wallet.issue_new_token(token_ticker, token_number_of_decimals, "http://uri", alice_address))
137+
token_id, _, _ = (await wallet.issue_new_token(token_ticker, token_number_of_decimals, "http://uri", alice_address))
138138
assert token_id is not None
139139
self.log.info(f"new token id: {token_id}")
140140
token_id_hex = node.test_functions_reveal_token_id(token_id)

test/functional/wallet_htlc_spend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async def async_test(self):
135135
assert_not_in("Tokens", balance)
136136

137137
# issue a valid token
138-
token_id, _ = (await wallet.issue_new_token("XXXX", 2, "http://uri", alice_address))
138+
token_id, _, _ = (await wallet.issue_new_token("XXXX", 2, "http://uri", alice_address))
139139
assert token_id is not None
140140
self.log.info(f"new token id: {token_id}")
141141

test/functional/wallet_orders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async def async_test(self):
141141
assert_not_in("Tokens", balance)
142142

143143
# issue a valid token
144-
token_id, _ = (await wallet.issue_new_token("XXXX", 2, "http://uri", alice_address))
144+
token_id, _, _ = (await wallet.issue_new_token("XXXX", 2, "http://uri", alice_address))
145145
assert token_id is not None
146146
self.log.info(f"new token id: {token_id}")
147147

test/functional/wallet_sweep_address.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,25 @@ def make_locked_output(pub_key_bytes):
172172

173173
# issue some tokens to also transfer
174174
tokens_address = await wallet.new_address()
175-
token_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", tokens_address)
175+
token_id, tx_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", tokens_address)
176176
assert token_id is not None
177+
assert tx_id is not None
177178
assert err is None
178-
self.log.info(f"new token id: {token_id}")
179+
self.log.info(f"new token id: {token_id} tx_id: {tx_id}")
180+
assert node.mempool_contains_tx(tx_id)
179181
block_id = self.generate_block()
180182
assert_in("Success", await wallet.sync())
181183
assert_in("The transaction was submitted successfully", await wallet.mint_tokens(token_id, tokens_address, 10000))
182184
addresses.append(tokens_address)
183185

184186
# issue some more tokens but freeze them
185187
frozen_tokens_address = await wallet.new_address()
186-
frozen_token_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", frozen_tokens_address)
188+
frozen_token_id, frozen_tx_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", frozen_tokens_address)
187189
assert frozen_token_id is not None
190+
assert frozen_tx_id is not None
188191
assert err is None
189192
self.log.info(f"new token id: {frozen_token_id}")
193+
assert node.mempool_contains_tx(frozen_tx_id)
190194
block_id = self.generate_block()
191195
assert_in("Success", await wallet.sync())
192196
assert_in("The transaction was submitted successfully", await wallet.mint_tokens(frozen_token_id, frozen_tokens_address, 10000))

test/functional/wallet_tokens.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,34 +117,39 @@ async def async_test(self):
117117
# invalid ticker
118118
# > max len
119119
invalid_ticker = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(random.randint(13, 20)))
120-
token_id, err = await wallet.issue_new_token(invalid_ticker, 2, "http://uri", address)
120+
token_id, tx_id, err = await wallet.issue_new_token(invalid_ticker, 2, "http://uri", address)
121121
assert token_id is None
122+
assert tx_id is None
122123
assert err is not None
123124
assert_in("Invalid ticker length", err)
124125
# non alphanumeric
125126
invalid_ticker = "asd" + random.choice(r"#$%&'()*+,-./:;<=>?@[]^_`{|}~")
126-
token_id, err = await wallet.issue_new_token("asd#", 2, "http://uri", address)
127+
token_id, tx_id, err = await wallet.issue_new_token("asd#", 2, "http://uri", address)
127128
assert token_id is None
129+
assert tx_id is None
128130
assert err is not None
129131
assert_in("Invalid character in token ticker", err)
130132

131133
# invalid url
132-
token_id, err = await wallet.issue_new_token("XXX", 2, "123 123", address)
134+
token_id, tx_id, err = await wallet.issue_new_token("XXX", 2, "123 123", address)
133135
assert token_id is None
136+
assert tx_id is None
134137
assert err is not None
135138
assert_in("Incorrect metadata URI", err)
136139

137140
# invalid num decimals
138-
token_id, err = await wallet.issue_new_token("XXX", 99, "http://uri", address)
141+
token_id, tx_id, err = await wallet.issue_new_token("XXX", 99, "http://uri", address)
139142
assert token_id is None
143+
assert tx_id is None
140144
assert err is not None
141145
assert_in("Too many decimals", err)
142146

143147
# issue a valid token
144148
valid_ticker = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(random.randint(1, 5)))
145149
num_decimals = random.randint(1, 5)
146-
token_id, err = await wallet.issue_new_token(valid_ticker, num_decimals, "http://uri", address)
150+
token_id, tx_id, err = await wallet.issue_new_token(valid_ticker, num_decimals, "http://uri", address)
147151
assert token_id is not None
152+
assert tx_id is not None
148153
assert err is None
149154
self.log.info(f"new token id: {token_id}")
150155

@@ -186,8 +191,9 @@ async def async_test(self):
186191
assert_in(f"{token_id} amount: {token_balance_str}", await wallet.get_balance())
187192

188193
## try to issue a new token, should fail with not enough coins
189-
token_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", address)
194+
token_id, tx_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", address)
190195
assert token_id is None
196+
assert tx_id is None
191197
assert err is not None
192198
assert_in("Not enough funds", err)
193199

test/functional/wallet_tokens_change_authority.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ async def async_test(self):
116116
address = await wallet.new_address()
117117

118118
# issue a valid token
119-
token_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", address, token_supply='lockable')
119+
token_id, tx_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", address, token_supply='lockable')
120120
assert token_id is not None
121+
assert tx_id is not None
121122
assert err is None
122123
self.log.info(f"new token id: {token_id}")
123124

test/functional/wallet_tokens_change_metadata_uri.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ async def async_test(self):
114114
# issue a valid token
115115
address = await wallet.new_address()
116116
metadata_uri = "http://uri"
117-
token_id, err = await wallet.issue_new_token("XXX", 2, metadata_uri, address, token_supply='lockable')
117+
token_id, tx_id, err = await wallet.issue_new_token("XXX", 2, metadata_uri, address, token_supply='lockable')
118118
assert token_id is not None
119+
assert tx_id is not None
119120
assert err is None
120121
self.log.info(f"new token id: {token_id}")
121122

test/functional/wallet_tokens_change_supply.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,32 +115,37 @@ async def async_test(self):
115115

116116
# invalid ticker
117117
# > max len
118-
token_id, err = await wallet.issue_new_token("aaabbbcccddde", 2, "http://uri", address)
118+
token_id, tx_id, err = await wallet.issue_new_token("aaabbbcccddde", 2, "http://uri", address)
119119
assert token_id is None
120+
assert tx_id is None
120121
assert err is not None
121122
assert_in("Invalid ticker length", err)
122123
# non alphanumeric
123-
token_id, err = await wallet.issue_new_token("asd#", 2, "http://uri", address)
124+
token_id, tx_id, err = await wallet.issue_new_token("asd#", 2, "http://uri", address)
124125
assert token_id is None
126+
assert tx_id is None
125127
assert err is not None
126128
assert_in("Invalid character in token ticker", err)
127129

128130
# invalid url
129-
token_id, err = await wallet.issue_new_token("XXX", 2, "123 123", address)
131+
token_id, tx_id, err = await wallet.issue_new_token("XXX", 2, "123 123", address)
130132
assert token_id is None
133+
assert tx_id is None
131134
assert err is not None
132135
assert_in("Incorrect metadata URI", err)
133136

134137
# invalid num decimals
135-
token_id, err = await wallet.issue_new_token("XXX", 99, "http://uri", address)
138+
token_id, tx_id, err = await wallet.issue_new_token("XXX", 99, "http://uri", address)
136139
assert token_id is None
140+
assert tx_id is None
137141
assert err is not None
138142
assert_in("Too many decimals", err)
139143

140144
# issue a valid token
141145
number_of_decimals = random.randrange(0, 4)
142-
token_id, err = await wallet.issue_new_token("XXX", number_of_decimals, "http://uri", address, 'lockable')
146+
token_id, tx_id, err = await wallet.issue_new_token("XXX", number_of_decimals, "http://uri", address, 'lockable')
143147
assert token_id is not None
148+
assert tx_id is not None
144149
assert err is None
145150
self.log.info(f"new token id: {token_id}")
146151

test/functional/wallet_tokens_freeze.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,21 @@ async def async_test(self):
116116
address = await wallet.new_address()
117117

118118
# issue a valid token
119-
token_id, err = await wallet.issue_new_token("XXX", 2, "http://uri", address)
119+
ticker = "XXX"
120+
decimals = 2
121+
url = "http://uri"
122+
token_id, tx_id, err = await wallet.issue_new_token(ticker, decimals, url, address)
120123
assert token_id is not None
124+
assert tx_id is not None
121125
assert err is None
122126
self.log.info(f"new token id: {token_id}")
123127

128+
hex_tx = await wallet.get_raw_signed_transaction(tx_id)
129+
summary = await wallet.inspect_transaction(hex_tx)
130+
assert_in(f"Ticker({ticker})", summary)
131+
assert_in(f"Decimals({decimals})", summary)
132+
assert_in("IsFreezable(Yes)", summary)
133+
124134
self.generate_block()
125135
assert_in("Success", await wallet.sync())
126136
assert_in("Coins amount: 400", await wallet.get_balance())

test/functional/wallet_tokens_transfer_from_multisig_addr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ async def setup_coins_and_tokens(self, node, wallet, coin_amount, foo_amount, ba
9595
self.log.debug(f'Created address: {address}')
9696

9797
# Create token foo.
98-
token_foo_id, err = await wallet.issue_new_token('FOO', 5, "http://uri", address)
98+
token_foo_id, token_foo_tx_id, err = await wallet.issue_new_token('FOO', 5, "http://uri", address)
9999
assert token_foo_id is not None
100+
assert token_foo_tx_id is not None
100101
assert err is None
101102
self.log.debug(f"token foo id: {token_foo_id}")
102103

103104
# Create token bar.
104-
token_bar_id, err = await wallet.issue_new_token('BAR', 10, "http://uri", address)
105+
token_bar_id, token_bar_tx_id, err = await wallet.issue_new_token('BAR', 10, "http://uri", address)
105106
assert token_bar_id is not None
107+
assert token_bar_tx_id is not None
106108
assert err is None
107109
self.log.debug(f"token bar id: {token_bar_id}")
108110

test/functional/wallet_tx_intent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ async def setup_currency(self, node, wallet, coin_amount, min_token_amount_per_u
108108
self.log.debug(f'token_issuer_address = {token_issuer_address}')
109109

110110
# Create the token.
111-
token_id, err = await wallet.issue_new_token('FOO', 5, "http://uri", token_issuer_address)
111+
token_id, tx_id, err = await wallet.issue_new_token('FOO', 5, "http://uri", token_issuer_address)
112112
assert token_id is not None
113+
assert tx_id is not None
113114
assert err is None
114115
self.log.debug(f"token id: {token_id}")
115116

0 commit comments

Comments
 (0)