Skip to content

Commit 7c2283c

Browse files
committed
add tests
1 parent 01322a5 commit 7c2283c

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

lazer/contracts/aptos/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,35 @@ This package is built using the Move language and Aptos framework.
44

55
`PythLazer` is an Aptos on-chain contract that allows consumers to easily verify Pyth Lazer updates for use on-chain.
66

7-
### Build and Test
7+
### Build, test, deploy
8+
9+
Install Aptos CLI and set it up:
10+
11+
```shell
12+
$ brew install
13+
$ aptos --version
14+
$ aptos init --network devnet
15+
```
16+
17+
Compile the contract and run tests:
818

919
```shell
1020
$ aptos move compile
1121
$ aptos move test
1222
```
1323

24+
Deploy to the network configured in your aptos profile:
25+
26+
```shell
27+
$ aptos move publish
28+
```
29+
30+
Invoke deployed contract functions on-chain:
31+
32+
```shell
33+
aptos move run --function-id 'default::pyth_lazer::update_trusted_signer' --args 'hex:0x8731685005cfb169b4da4bbfab0c91c5ba59508bbd6d26990ee2be7225cb34d1' 'u64:9999999999'
34+
```
35+
1436
### Error Handling
1537

1638
The contract uses the following error codes:

lazer/contracts/aptos/tests/pyth_lazer_tests.move

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
#[test_only]
22
module pyth_lazer::pyth_lazer_tests {
33
use std::signer;
4-
use std::string;
54
use aptos_framework::account;
65
use aptos_framework::coin;
76
use aptos_framework::timestamp;
87
use aptos_framework::aptos_coin::AptosCoin;
98
use aptos_std::ed25519;
109
use pyth_lazer::pyth_lazer;
10+
use std::vector;
11+
use std::debug;
12+
use std::string::{String,utf8};
1113

1214
// Test accounts
13-
const TOP_AUTHORITY: address = @0x123;
15+
const TOP_AUTHORITY: address = @0x3374049c3b46a907ff2fc6b62af51975fb9dc572b7e73eb1b255ed5edcd7cee0;
1416
const TREASURY: address = @0x456;
1517
const USER: address = @0x789;
1618

1719
// 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";
2123

2224
#[test_only]
2325
fun setup_aptos_coin(framework: &signer): coin::MintCapability<AptosCoin> {
@@ -36,6 +38,7 @@ module pyth_lazer::pyth_lazer_tests {
3638
fun setup(): (signer, signer, signer) {
3739
// Create test accounts
3840
let framework = account::create_account_for_test(@aptos_framework);
41+
let lazer_contract = account::create_account_for_test(@pyth_lazer);
3942
let top_authority = account::create_account_for_test(TOP_AUTHORITY);
4043
let treasury = account::create_account_for_test(TREASURY);
4144
let user = account::create_account_for_test(USER);
@@ -57,17 +60,34 @@ module pyth_lazer::pyth_lazer_tests {
5760
timestamp::set_time_has_started_for_testing(&framework);
5861

5962
// Initialize contract
60-
pyth_lazer::initialize(&top_authority, TOP_AUTHORITY, TREASURY);
63+
pyth_lazer::initialize(&lazer_contract, TOP_AUTHORITY, TREASURY);
6164

6265
(top_authority, treasury, user)
6366
}
6467

6568
#[test]
6669
fun test_initialize() {
67-
let (top_authority, _treasury, _) = setup();
70+
let (_top_authority, _treasury, _) = setup();
6871
// Contract is already initialized in setup
6972
}
7073

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+
7191
#[test]
7292
fun test_update_add_signer() {
7393
let (top_authority, _treasury, _) = setup();

0 commit comments

Comments
 (0)