1
1
#[test_only]
2
2
module pyth_lazer ::pyth_lazer_tests {
3
3
use std::signer;
4
- use std::string;
5
4
use aptos_framework::account;
6
5
use aptos_framework::coin;
7
6
use aptos_framework::timestamp;
8
7
use aptos_framework::aptos_coin::AptosCoin ;
9
8
use aptos_std::ed25519;
10
9
use pyth_lazer::pyth_lazer;
10
+ use std::vector;
11
+ use std::debug;
12
+ use std::string::{String ,utf8};
11
13
12
14
// Test accounts
13
- const TOP_AUTHORITY : address = @0x123 ;
15
+ const TOP_AUTHORITY : address = @0x3374049c3b46a907ff2fc6b62af51975fb9dc572b7e73eb1b255ed5edcd7cee0 ;
14
16
const TREASURY : address = @0x456 ;
15
17
const USER : address = @0x789 ;
16
18
17
19
// Test data
18
- const TEST_PUBKEY : vector <u8 > = x"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef ";
19
- const TEST_MESSAGE : vector <u8 > = x" deadbeef ";
20
- const TEST_SIGNATURE : vector <u8 > = x"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef ";
20
+ const TEST_PUBKEY : vector <u8 > = x"3374049c3b46a907ff2fc6b62af51975fb9dc572b7e73eb1b255ed5edcd7cee0 ";
21
+ const TEST_MESSAGE : vector <u8 > = b" test message ";
22
+ const TEST_SIGNATURE : vector <u8 > = x"20ebb15d70abc18abf636d77fa86a89e32596f90569b09e732b556bbc2f8afea07feff8d1beb18f7acd7ef1d3f914163fe03a3b4206f61f932e2d22a21278a01 ";
21
23
22
24
#[test_only]
23
25
fun setup_aptos_coin (framework: &signer ): coin::MintCapability <AptosCoin > {
@@ -36,6 +38,7 @@ module pyth_lazer::pyth_lazer_tests {
36
38
fun setup (): (signer , signer , signer ) {
37
39
// Create test accounts
38
40
let framework = account::create_account_for_test (@aptos_framework );
41
+ let lazer_contract = account::create_account_for_test (@pyth_lazer );
39
42
let top_authority = account::create_account_for_test (TOP_AUTHORITY );
40
43
let treasury = account::create_account_for_test (TREASURY );
41
44
let user = account::create_account_for_test (USER );
@@ -57,17 +60,34 @@ module pyth_lazer::pyth_lazer_tests {
57
60
timestamp::set_time_has_started_for_testing (&framework);
58
61
59
62
// Initialize contract
60
- pyth_lazer::initialize (&top_authority , TOP_AUTHORITY , TREASURY );
63
+ pyth_lazer::initialize (&lazer_contract , TOP_AUTHORITY , TREASURY );
61
64
62
65
(top_authority, treasury, user)
63
66
}
64
67
65
68
#[test]
66
69
fun test_initialize () {
67
- let (top_authority , _treasury, _) = setup ();
70
+ let (_top_authority , _treasury, _) = setup ();
68
71
// Contract is already initialized in setup
69
72
}
70
73
74
+ #[test]
75
+ fun test_verify_message_success () {
76
+ let (top_authority, _treasury, user) = setup ();
77
+
78
+ // Add a valid signer
79
+ let expires_at = timestamp::now_seconds () + 1000 ;
80
+ pyth_lazer::update_trusted_signer (&top_authority, TEST_PUBKEY , expires_at);
81
+
82
+ // Create a valid ed25519 signature
83
+ let signature = ed25519::new_signature_from_bytes (TEST_SIGNATURE );
84
+ let pubkey = ed25519::new_unvalidated_public_key_from_bytes (TEST_PUBKEY );
85
+ assert !(ed25519::signature_verify_strict (&signature, &pubkey, TEST_MESSAGE ), 0 );
86
+
87
+ // This should succeed as we have a valid signer and sufficient fee
88
+ pyth_lazer::verify_message (&user, TEST_MESSAGE , TEST_SIGNATURE , TEST_PUBKEY );
89
+ }
90
+
71
91
#[test]
72
92
fun test_update_add_signer () {
73
93
let (top_authority, _treasury, _) = setup ();
0 commit comments