def test_incorrect_checksum(): with pytest.raises(ValidationError, match=".* not a valid BIP39 mnemonic phrase!"): # Moved 12th word of valid phrase to be 1st Account.from_mnemonic( "student into trim cross then helmet popular suit hammer cart shrug oval" )
def test_compatibility(seed, language, account_path): mnemonic = Mnemonic(language).to_mnemonic(seed) acct = Account.from_mnemonic(mnemonic, account_path=account_path) # NOTE Must do `cd tests/integration/ethers-cli && npm install -g . ethers_cli = subprocess.run( ['ethers-cli', '-m', mnemonic, '-l', language, '-p', account_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) if ethers_cli.stderr: raise IOError(ethers_cli.stderr.decode("utf-8")) ethers_address = ethers_cli.stdout.decode("utf-8").strip() assert acct.address == ethers_address
def test_bad_account_path1(): with pytest.raises(ValidationError, match="Path is not valid.*"): Account.from_mnemonic( "finish oppose decorate face calm tragic certain desk hour urge dinosaur mango", account_path='not an account path')
def test_malformed_seed(): with pytest.raises(ValidationError, match=".* not a valid BIP39 mnemonic phrase!"): # Missing 12th word Account.from_mnemonic( "into trim cross then helmet popular suit hammer cart shrug oval")
def test_incorrect_size(): with pytest.raises(ValidationError, match="Language not detected .*"): Account.from_mnemonic("this is not a seed phrase")
def test_bad_passphrase(): a1, mnemonic = Account.create_with_mnemonic(passphrase="My passphrase") a2 = Account.from_mnemonic(mnemonic, passphrase="Not my passphrase") assert a1.address != a2.address
def test_account_restore(): a1, mnemonic = Account.create_with_mnemonic(num_words=24, passphrase="TESTING") a2 = Account.from_mnemonic(mnemonic, passphrase="TESTING") assert a1.address == a2.address
def test_account_derivation(mnemonic, account_path, expected_address): a = Account.from_mnemonic(mnemonic, account_path=account_path) assert a.address == expected_address