Skip to content

Commit d2b734a

Browse files
committed
test: add test_verify_invalid_message_fails
1 parent d154842 commit d2b734a

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

lazer/contracts/aptos/tests/pyth_lazer_tests.move

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ module pyth_lazer::pyth_lazer_tests {
77
use aptos_framework::timestamp;
88
use aptos_framework::aptos_coin::AptosCoin;
99
use aptos_std::ed25519;
10-
use pyth_lazer::pyth_lazer::{Self, EINVALID_SIGNER, EINSUFFICIENT_FEE};
10+
use pyth_lazer::pyth_lazer::{
11+
Self,
12+
EINVALID_SIGNER,
13+
EINSUFFICIENT_FEE,
14+
EINVALID_SIGNATURE
15+
};
1116

1217
// Test accounts
1318
const TOP_AUTHORITY: address =
@@ -66,7 +71,7 @@ module pyth_lazer::pyth_lazer_tests {
6671
}
6772

6873
#[test]
69-
fun test_verify_message_succeeds() {
74+
fun test_verify_valid_message_succeeds() {
7075
let (top_authority, _treasury, user) = setup();
7176

7277
// Add a valid signer
@@ -90,6 +95,28 @@ module pyth_lazer::pyth_lazer_tests {
9095
);
9196
}
9297

98+
#[test]
99+
#[expected_failure(abort_code = EINVALID_SIGNATURE)]
100+
fun test_verify_invalid_message_fails() {
101+
let (top_authority, _treasury, user) = setup();
102+
103+
// Add a valid signer
104+
let expires_at = timestamp::now_seconds() + 1000;
105+
pyth_lazer::update_trusted_signer(&top_authority, TEST_PUBKEY, expires_at);
106+
107+
// Use a different message than what was signed
108+
let invalid_message = b"different message";
109+
110+
// This should fail with EINVALID_SIGNATURE since the signature
111+
// was created for TEST_MESSAGE, not invalid_message
112+
pyth_lazer::verify_message(
113+
&user,
114+
invalid_message,
115+
TEST_SIGNATURE,
116+
TEST_PUBKEY
117+
);
118+
}
119+
93120
#[test]
94121
fun test_add_update_remove_signers_succeeds() {
95122
let (top_authority, _treasury, _) = setup();

0 commit comments

Comments
 (0)