Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
test: add more tests for var near amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Feb 22, 2024
1 parent da202e5 commit 18efb79
Show file tree
Hide file tree
Showing 264 changed files with 279 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub mod parsing {
function_call::FunctionCallCommon,
stake::Stake,
transfer::Transfer,
Action, ONE_NEAR,
Action,
};
pub use common::message_discriminant::MessageDiscriminant;
pub use common::tx_public_key::TxPublicKey;
Expand Down
3 changes: 0 additions & 3 deletions src/parsing/types/common/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ pub type Nonce = u64;
/// Height of the block.
pub type BlockHeight = u64;

pub const ONE_NEAR: u128 = 10_u128.pow(24);
pub const ONE_MILLINEAR: u128 = 10_u128.pow(21);

pub mod add_key;
pub mod create_account;
pub mod delete_account;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_transfer/0_1_sign/00002.png
Binary file modified tests/snapshots/nanosp/test_sign_transfer/0_1_sign/00002.png
Binary file modified tests/snapshots/nanox/test_sign_transfer/0_1_sign/00002.png
174 changes: 174 additions & 0 deletions tests/test_sign_transaction/test_function_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,177 @@ def test_sign_function_call_binary_hexdump_after_utf8_error(
),
]
generic_test_sign(client, chunks, navigator, test_name)


def test_sign_function_call_amount_1(firmware, backend, navigator: Navigator, test_name):
"""
1 yoctoNEAR
Transaction {
signer_id: AccountId(
"c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f",
),
public_key: ed25519:EFr6nRvgKKeteKoEH7hudt8UHYiu94Liq2yMM7x2AU9U,
nonce: 103595482000005,
receiver_id: AccountId(
"dc7e34eecec3096a4a661e10932834f801149c49dba9b93322f6d9de18047f9c",
),
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
FunctionCall(
FunctionCallAction {
method_name: saturating_call_signed,
args: eyJrZXkiOiJ2YWx1ZSJ9,
gas: 127127122121,
deposit: 1,
},
),
],
}
"""
client = Nearbackend(backend)
chunks = [
AsyncAPDU(
data=bytes.fromhex(
"80020057fa8000002c8000018d800000008000000080000001400000006334663539343165383165303731633266643164616532653731666433643835396434363234383433393164396139306266323139323131646362623332306600c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00004000000064633765333465656365633330393661346136363165313039333238333466383031313439633439646261396239333332326636643964653138303437663963ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a72583101000000021600000073617475726174696e675f63"
),
navigable_conditions=NavigableConditions(
value=["Continue to actions"],
),
expected_response=RAPDU(
SW_OK,
bytes(),
),
),
AsyncAPDU(
data=bytes.fromhex(
"8002805735616c6c5f7369676e65640f0000007b226b6579223a2276616c7565227dc9f05d991d00000001000000000000000000000000000000"
),
navigable_conditions=NavigableConditions(
value=["Sign"],
),
expected_response=RAPDU(
SW_OK,
# signature
bytes.fromhex(
"19dfc1496e17b979a79b5442eed52ab79112eaf35d98638fdd56c6bbdf3c327a8cf1f1a6702e93db757200dfcef18ac2b62db1bf3f6f6c1772be60b6a44d8004"
),
),
),
]
generic_test_sign(client, chunks, navigator, test_name)


def test_sign_function_call_amount_2(firmware, backend, navigator: Navigator, test_name):
"""
1M NEAR
Transaction {
signer_id: AccountId(
"c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f",
),
public_key: ed25519:EFr6nRvgKKeteKoEH7hudt8UHYiu94Liq2yMM7x2AU9U,
nonce: 103595482000005,
receiver_id: AccountId(
"dc7e34eecec3096a4a661e10932834f801149c49dba9b93322f6d9de18047f9c",
),
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
FunctionCall(
FunctionCallAction {
method_name: saturating_call_signed,
args: eyJrZXkiOiJ2YWx1ZSJ9,
gas: 127127122121,
deposit: 1000000000000000000000000000000,
},
),
],
}
"""
client = Nearbackend(backend)
chunks = [
AsyncAPDU(
data=bytes.fromhex(
"80020057fa8000002c8000018d800000008000000080000001400000006334663539343165383165303731633266643164616532653731666433643835396434363234383433393164396139306266323139323131646362623332306600c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00004000000064633765333465656365633330393661346136363165313039333238333466383031313439633439646261396239333332326636643964653138303437663963ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a72583101000000021600000073617475726174696e675f63"
),
navigable_conditions=NavigableConditions(
value=["Continue to actions"],
),
expected_response=RAPDU(
SW_OK,
bytes(),
),
),
AsyncAPDU(
data=bytes.fromhex(
"8002805735616c6c5f7369676e65640f0000007b226b6579223a2276616c7565227dc9f05d991d00000000000040eaed7446d09c2c9f0c000000"
),
navigable_conditions=NavigableConditions(
value=["Sign"],
),
expected_response=RAPDU(
SW_OK,
# signature
bytes.fromhex(
"f2f7fef77b3ac0371b05586a831d022783f7edbec25c40cf65894fcc53db1fdefede704ce8132980f9038ef2e5832c8b9377c68dac820e08743ff77554965a0f"
),
),
),
]
generic_test_sign(client, chunks, navigator, test_name)


def test_sign_function_call_amount_3(firmware, backend, navigator: Navigator, test_name):
"""
0.00001 NEAR
Transaction {
signer_id: AccountId(
"c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f",
),
public_key: ed25519:EFr6nRvgKKeteKoEH7hudt8UHYiu94Liq2yMM7x2AU9U,
nonce: 103595482000005,
receiver_id: AccountId(
"dc7e34eecec3096a4a661e10932834f801149c49dba9b93322f6d9de18047f9c",
),
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
FunctionCall(
FunctionCallAction {
method_name: saturating_call_signed,
args: eyJrZXkiOiJ2YWx1ZSJ9,
gas: 127127122121,
deposit: 10000000000000000000,
},
),
],
}
"""
client = Nearbackend(backend)
chunks = [
AsyncAPDU(
data=bytes.fromhex(
"80020057fa8000002c8000018d800000008000000080000001400000006334663539343165383165303731633266643164616532653731666433643835396434363234383433393164396139306266323139323131646362623332306600c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00004000000064633765333465656365633330393661346136363165313039333238333466383031313439633439646261396239333332326636643964653138303437663963ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a72583101000000021600000073617475726174696e675f63"
),
navigable_conditions=NavigableConditions(
value=["Continue to actions"],
),
expected_response=RAPDU(
SW_OK,
bytes(),
),
),
AsyncAPDU(
data=bytes.fromhex(
"8002805735616c6c5f7369676e65640f0000007b226b6579223a2276616c7565227dc9f05d991d0000000000e8890423c78a0000000000000000"
),
navigable_conditions=NavigableConditions(
value=["Sign"],
),
expected_response=RAPDU(
SW_OK,
# signature
bytes.fromhex(
"6c3bdf78ca23ea3c0c8797d90fb384293c4396487f2de5094b20e69232bf67a5a5da142e953ef4b7306aac53498befac0afa7b7877589651a711960712ea560b"
),
),
),
]
generic_test_sign(client, chunks, navigator, test_name)
57 changes: 57 additions & 0 deletions tests/test_sign_transaction/test_stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

def test_sign_stake(firmware, backend, navigator: Navigator, test_name):
"""
1.16 NEAR
Transaction {
signer_id: AccountId(
"c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f",
Expand Down Expand Up @@ -62,3 +63,59 @@ def test_sign_stake(firmware, backend, navigator: Navigator, test_name):
),
]
generic_test_sign(client, chunks, navigator, test_name)


def test_sign_stake_1(firmware, backend, navigator: Navigator, test_name):
"""
1M NEAR
Transaction {
signer_id: AccountId(
"c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f",
),
public_key: ed25519:EFr6nRvgKKeteKoEH7hudt8UHYiu94Liq2yMM7x2AU9U,
nonce: 103595482000005,
receiver_id: AccountId(
"dc7e34eecec3096a4a661e10932834f801149c49dba9b93322f6d9de18047f9c",
),
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
Stake(
StakeAction {
stake: 1000000000000000000000000000000,
public_key: secp256k1:2xV3hzGShUE3X5jE9jmAyFC67GfgwAUo5FoBJ79Zh84Z5Ubdxy94Ka73EWwrFg5FbVYAvtdqJK77P6CAdyMkEnca,
},
),
],
}
"""
client = Nearbackend(backend)
chunks = [
AsyncAPDU(
data=bytes.fromhex(
"80020057fa8000002c8000018d800000008000000080000001400000006334663539343165383165303731633266643164616532653731666433643835396434363234383433393164396139306266323139323131646362623332306600c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00004000000064633765333465656365633330393661346136363165313039333238333466383031313439633439646261396239333332326636643964653138303437663963ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a725831010000000400000040eaed7446d09c2c9f0c000000"
),
navigable_conditions=NavigableConditions(
value=["Continue to actions"],
),
expected_response=RAPDU(
SW_OK,
bytes(),
),
),
AsyncAPDU(
data=bytes.fromhex(
"80028057410161dd29ada831ab894b465a656c86c557c5008156da0909c4a281f5c8d9ee3de837534833badf7ad41a5e83071908af7d4f2ae835c9d9aceb48cfb47a4c96509b"
),
navigable_conditions=NavigableConditions(
value=["Sign"],
),
expected_response=RAPDU(
SW_OK,
# signature
bytes.fromhex(
"02f7cdb55e55b8a7efe9d87b6a7971b4fc816c2a1e17262a544a12a599789d1e457fb40bef286f9dcaf709f751e7869a19fcccec9b2156e293ee1f6595a23406"
),
),
),
]
generic_test_sign(client, chunks, navigator, test_name)
50 changes: 47 additions & 3 deletions tests/test_sign_transaction/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

def test_sign_transfer(firmware, backend, navigator: Navigator, test_name):
"""
1234.56 NEAR
Transaction {
signer_id: AccountId(
"c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f",
Expand All @@ -25,7 +26,7 @@ def test_sign_transfer(firmware, backend, navigator: Navigator, test_name):
actions: [
Transfer(
TransferAction {
deposit: 150000000000000000000000,
deposit: 1234560000000000000000000000,
},
),
],
Expand All @@ -35,7 +36,7 @@ def test_sign_transfer(firmware, backend, navigator: Navigator, test_name):
chunks = [
AsyncAPDU(
data=bytes.fromhex(
"80028057fa8000002c8000018d800000008000000080000001400000006334663539343165383165303731633266643164616532653731666433643835396434363234383433393164396139306266323139323131646362623332306600c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00004000000064633765333465656365633330393661346136363165313039333238333466383031313439633439646261396239333332326636643964653138303437663963ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a72583101000000030000c071f0d12b84c31f000000000000"
"80028057fa8000002c8000018d800000008000000080000001400000006334663539343165383165303731633266643164616532653731666433643835396434363234383433393164396139306266323139323131646362623332306600c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00004000000064633765333465656365633330393661346136363165313039333238333466383031313439633439646261396239333332326636643964653138303437663963ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a72583101000000030000001049f203b43f34fd0300000000"
),
navigable_conditions=NavigableConditions(
value=["Continue to actions", "Sign"],
Expand All @@ -44,7 +45,50 @@ def test_sign_transfer(firmware, backend, navigator: Navigator, test_name):
SW_OK,
# signature
bytes.fromhex(
"f735265a9b6f2653d223705c79ab0354ee6606f6e1ccb44dff3cdea1c553fb62925d717c97d128e954403cd99aafb1108d4fe96cf425fcbb3d11a3ccc5da0108"
"a8cc807ff4e83df0a5834af232550ccd15f09f829e0e73a88b6175e41d001085f2087d0b03fb36faf07d3b261d2d11a0e7b92a244c0dfd57e6daa3b91ae42205"
),
),
)
]
generic_test_sign(client, chunks, navigator, test_name)


def test_sign_transfer_1(firmware, backend, navigator: Navigator, test_name):
"""
1M NEAR
Transaction {
signer_id: AccountId(
"c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f",
),
public_key: ed25519:EFr6nRvgKKeteKoEH7hudt8UHYiu94Liq2yMM7x2AU9U,
nonce: 103595482000005,
receiver_id: AccountId(
"dc7e34eecec3096a4a661e10932834f801149c49dba9b93322f6d9de18047f9c",
),
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
Transfer(
TransferAction {
deposit: 1000000000000000000000000000000,
},
),
],
}
"""
client = Nearbackend(backend)
chunks = [
AsyncAPDU(
data=bytes.fromhex(
"80028057fa8000002c8000018d800000008000000080000001400000006334663539343165383165303731633266643164616532653731666433643835396434363234383433393164396139306266323139323131646362623332306600c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f85aae733385e00004000000064633765333465656365633330393661346136363165313039333238333466383031313439633439646261396239333332326636643964653138303437663963ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a725831010000000300000040eaed7446d09c2c9f0c000000"
),
navigable_conditions=NavigableConditions(
value=["Continue to actions", "Sign"],
),
expected_response=RAPDU(
SW_OK,
# signature
bytes.fromhex(
"fffaa38d92c5b0c15558abbd1d40f6024598d77ccb986c0faa6487a4f0b51358862e2ae63a23e97c34cc5e885cf3e90bdfea4286998ecb1865a399ca5630d60c"
),
),
)
Expand Down

0 comments on commit 18efb79

Please sign in to comment.