Skip to content

Commit e9731ef

Browse files
committed
Merge develop while preserving signing regressions
2 parents 006906f + 2bf8790 commit e9731ef

1 file changed

Lines changed: 38 additions & 12 deletions

File tree

tests/test_msg_solana_signtx.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,56 +356,82 @@ def test_solana_sign_set_authority_requires_advanced_mode(self):
356356

357357
def test_solana_sign_stake_authorize_clearsigns(self):
358358
"""StakeAuthorize clear-signs, showing the role (staker/withdrawer) and
359-
the new authority."""
359+
the new authority. Canonical account layout: [0]=stake account,
360+
[1]=Clock sysvar, [2]=[SIGNER] current authority -- the Clock sysvar
361+
must be present so the signer lands at the real index 2, not 1."""
360362
self.requires_fullFeature()
361363
self.setup_mnemonic_allallall()
362364
from_pubkey = self._get_from_pubkey()
365+
clock_sysvar = b'\xC1' * 32
363366
current_auth = b'\x77' * 32
364367
new_auth = b'\x88' * 32
365368
# Authorize (type=1 LE u32) + new authority(32) + StakeAuthorize role (0=staker)
366369
instr_data = struct.pack('<I', 1) + new_auth + struct.pack('<I', 0)
367-
raw_tx = self._build_tx(from_pubkey, [current_auth], self.STAKE_PROGRAM, instr_data)
370+
raw_tx = self._build_tx(from_pubkey, [clock_sysvar, current_auth],
371+
self.STAKE_PROGRAM, instr_data)
368372
resp = self.client.call(messages.SolanaSignTx(
369373
address_n=parse_path("m/44'/501'/0'/0'"), raw_tx=raw_tx))
370374
self.assertEqual(len(resp.signature), 64)
371375

372376
def test_solana_sign_stake_delegate(self):
373-
"""Stake delegate — OLED shows 'Delegate stake?'."""
377+
"""Stake delegate — OLED shows 'Delegate stake?'. Canonical account
378+
layout: [0]=stake account, [1]=vote account, [2]=Clock sysvar,
379+
[3]=StakeHistory sysvar, [4]=stake config account, [5]=[SIGNER] stake
380+
authority."""
374381
self.requires_fullFeature()
375382
self.setup_mnemonic_allallall()
376383
from_pubkey = self._get_from_pubkey()
377-
stake_account = b'\x55' * 32
378384
vote_account = b'\x66' * 32
385+
clock_sysvar = b'\xC1' * 32
386+
stake_history_sysvar = b'\xC2' * 32
387+
stake_config = b'\xC3' * 32
388+
authority = b'\x99' * 32
379389
# Stake Delegate: type=2 (LE u32)
380390
instr_data = struct.pack('<I', 2)
381-
raw_tx = self._build_tx(from_pubkey, [stake_account, vote_account],
382-
self.STAKE_PROGRAM, instr_data)
391+
raw_tx = self._build_tx(
392+
from_pubkey,
393+
[vote_account, clock_sysvar, stake_history_sysvar, stake_config,
394+
authority],
395+
self.STAKE_PROGRAM, instr_data)
383396
resp = self.client.call(messages.SolanaSignTx(
384397
address_n=parse_path("m/44'/501'/0'/0'"), raw_tx=raw_tx))
385398
self.assertEqual(len(resp.signature), 64)
386399

387400
def test_solana_sign_stake_withdraw(self):
388-
"""Stake withdraw — OLED shows 'Withdraw [amount] from stake?'."""
401+
"""Stake withdraw — OLED shows 'Withdraw [amount] from stake?'.
402+
Canonical account layout: [0]=stake account, [1]=recipient,
403+
[2]=Clock sysvar, [3]=StakeHistory sysvar, [4]=[SIGNER] withdraw
404+
authority."""
389405
self.requires_fullFeature()
390406
self.setup_mnemonic_allallall()
391407
from_pubkey = self._get_from_pubkey()
392-
stake_account = b'\x55' * 32
408+
recipient = b'\x55' * 32
409+
clock_sysvar = b'\xC1' * 32
410+
stake_history_sysvar = b'\xC2' * 32
411+
authority = b'\x99' * 32
393412
# Stake Withdraw: type=4 (LE u32) + lamports (LE u64)
394413
instr_data = struct.pack('<I', 4) + struct.pack('<Q', 2000000000) # 2 SOL
395-
raw_tx = self._build_tx(from_pubkey, [stake_account], self.STAKE_PROGRAM, instr_data)
414+
raw_tx = self._build_tx(
415+
from_pubkey,
416+
[recipient, clock_sysvar, stake_history_sysvar, authority],
417+
self.STAKE_PROGRAM, instr_data)
396418
resp = self.client.call(messages.SolanaSignTx(
397419
address_n=parse_path("m/44'/501'/0'/0'"), raw_tx=raw_tx))
398420
self.assertEqual(len(resp.signature), 64)
399421

400422
def test_solana_sign_stake_deactivate(self):
401-
"""Stake deactivate — OLED shows 'Deactivate stake?'."""
423+
"""Stake deactivate — OLED shows 'Deactivate stake?'. Canonical
424+
account layout: [0]=stake account, [1]=Clock sysvar, [2]=[SIGNER]
425+
stake authority."""
402426
self.requires_fullFeature()
403427
self.setup_mnemonic_allallall()
404428
from_pubkey = self._get_from_pubkey()
405-
stake_account = b'\x55' * 32
429+
clock_sysvar = b'\xC1' * 32
430+
authority = b'\x99' * 32
406431
# Stake Deactivate: type=5 (LE u32)
407432
instr_data = struct.pack('<I', 5)
408-
raw_tx = self._build_tx(from_pubkey, [stake_account], self.STAKE_PROGRAM, instr_data)
433+
raw_tx = self._build_tx(from_pubkey, [clock_sysvar, authority],
434+
self.STAKE_PROGRAM, instr_data)
409435
resp = self.client.call(messages.SolanaSignTx(
410436
address_n=parse_path("m/44'/501'/0'/0'"), raw_tx=raw_tx))
411437
self.assertEqual(len(resp.signature), 64)

0 commit comments

Comments
 (0)