Skip to content

Commit d8c69a6

Browse files
authored
[sui 6/x] - Pyth unit tests (#757)
* state getters and setters, change Move.toml dependency to sui/integration_v2 * finish state.move * add new line to pyth * use deployer cap pattern for state module * sui pyth * update price feeds, dynamic object fields, Sui object PriceInfoObject * register price info object with pyth state after creation * sui governance * some newlines * error codes * update and comment * unit tests for pyth.move, add UpgradeCap to Pyth State (will be used for contract upgrades) * updates * test_get_update_fee test passes * fix test_get_update_fee and test_update_price_feeds_corrupt_vaa * test_update_price_feeds_invalid_data_source * test_create_and_update_price_feeds * test_create_and_update_price_feeds_success and test_create_and_update_price_feeds_price_info_object_not_found_failure * test_update_cache * update * test_update_cache_old_update * update_price_feeds_if_fresh * comment
1 parent f541ffa commit d8c69a6

File tree

10 files changed

+864
-33
lines changed

10 files changed

+864
-33
lines changed

target_chains/sui/contracts/Move.lock

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# @generated by Move, please check-in and do not edit manually.
2+
3+
[move]
4+
version = 0
5+
6+
dependencies = [
7+
{ name = "Sui" },
8+
{ name = "Wormhole" },
9+
]
10+
11+
[[move.package]]
12+
name = "MoveStdlib"
13+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "81dbcf2b6cab07d623a1012bf31daf658963c765", subdir = "crates/sui-framework/packages/move-stdlib" }
14+
15+
[[move.package]]
16+
name = "Sui"
17+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "81dbcf2b6cab07d623a1012bf31daf658963c765", subdir = "crates/sui-framework/packages/sui-framework" }
18+
19+
dependencies = [
20+
{ name = "MoveStdlib" },
21+
]
22+
23+
[[move.package]]
24+
name = "Wormhole"
25+
source = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "sui/integration_v2", subdir = "sui/wormhole" }
26+
27+
dependencies = [
28+
{ name = "Sui" },
29+
]

target_chains/sui/contracts/Move.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = "0.0.1"
55
[dependencies.Sui]
66
git = "https://github.com/MystenLabs/sui.git"
77
subdir = "crates/sui-framework/packages/sui-framework"
8-
rev = "82c9c80c11488858f1d3930f47ec9f335a566683"
8+
rev = "ddfc3fa0768a38286787319603a5458a9ff91cc1"
99

1010
[dependencies.Wormhole]
1111
git = "https://github.com/wormhole-foundation/wormhole.git"

target_chains/sui/contracts/sources/governance/governance.move

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module pyth::governance {
2-
use sui::tx_context::{TxContext};
2+
use sui::clock::{Clock};
33

44
use pyth::data_source::{Self};
55
use pyth::governance_instruction;
@@ -19,14 +19,14 @@ module pyth::governance {
1919
const E_INVALID_GOVERNANCE_ACTION: u64 = 1;
2020
const E_INVALID_GOVERNANCE_DATA_SOURCE: u64 = 2;
2121
const E_INVALID_GOVERNANCE_SEQUENCE_NUMBER: u64 = 3;
22-
22+
2323
public entry fun execute_governance_instruction(
2424
pyth_state : &mut State,
2525
worm_state: &WormState,
2626
vaa_bytes: vector<u8>,
27-
ctx: &mut TxContext
27+
clock: &Clock
2828
) {
29-
let parsed_vaa = parse_and_verify_governance_vaa(pyth_state, worm_state, vaa_bytes, ctx);
29+
let parsed_vaa = parse_and_verify_governance_vaa(pyth_state, worm_state, vaa_bytes, clock);
3030
let instruction = governance_instruction::from_byte_vec(vaa::take_payload(parsed_vaa));
3131

3232
// Dispatch the instruction to the appropiate handler
@@ -53,9 +53,9 @@ module pyth::governance {
5353
pyth_state: &mut State,
5454
worm_state: &WormState,
5555
bytes: vector<u8>,
56-
ctx: &mut TxContext
56+
clock: &Clock,
5757
): VAA {
58-
let parsed_vaa = vaa::parse_and_verify(worm_state, bytes, ctx);
58+
let parsed_vaa = vaa::parse_and_verify(worm_state, bytes, clock);
5959

6060
// Check that the governance data source is valid
6161
assert!(

target_chains/sui/contracts/sources/governance/governance_action.move

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module pyth::governance_action {
66
const SET_DATA_SOURCES: u8 = 2;
77
const SET_UPDATE_FEE: u8 = 3;
88
const SET_STALE_PRICE_THRESHOLD: u8 = 4;
9+
910
const E_INVALID_GOVERNANCE_ACTION: u64 = 5;
1011

1112
struct GovernanceAction has copy, drop {

target_chains/sui/contracts/sources/governance/governance_instruction.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module pyth::governance_instruction {
99
const E_INVALID_GOVERNANCE_MODULE: u64 = 0;
1010
const E_INVALID_GOVERNANCE_MAGIC_VALUE: u64 = 1;
1111
const E_TARGET_CHAIN_MISMATCH: u64 = 2;
12-
12+
1313
struct GovernanceInstruction {
1414
module_: u8,
1515
action: GovernanceAction,

target_chains/sui/contracts/sources/governance/set_data_sources.move

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module pyth::set_data_sources {
33

44
use wormhole::cursor;
55
use wormhole::external_address::{Self};
6+
use wormhole::bytes32::{Self};
67

78
use pyth::deserialize;
89
use pyth::data_source::{Self, DataSource};
@@ -28,7 +29,7 @@ module pyth::set_data_sources {
2829
let i = 0;
2930
while (i < data_sources_count) {
3031
let emitter_chain_id = deserialize::deserialize_u16(&mut cursor);
31-
let emitter_address = external_address::from_bytes(deserialize::deserialize_vector(&mut cursor, 32));
32+
let emitter_address = external_address::new(bytes32::from_bytes(deserialize::deserialize_vector(&mut cursor, 32)));
3233
vector::push_back(&mut sources, data_source::new((emitter_chain_id as u64), emitter_address));
3334

3435
i = i + 1;

target_chains/sui/contracts/sources/governance/set_governance_data_source.move

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module pyth::set_governance_data_source {
55

66
use wormhole::cursor;
77
use wormhole::external_address::{Self, ExternalAddress};
8+
use wormhole::bytes32::{Self};
89
//use wormhole::state::{Self}
910

1011
friend pyth::governance;
@@ -24,7 +25,7 @@ module pyth::set_governance_data_source {
2425
fun from_byte_vec(bytes: vector<u8>): SetGovernanceDataSource {
2526
let cursor = cursor::new(bytes);
2627
let emitter_chain_id = deserialize::deserialize_u16(&mut cursor);
27-
let emitter_address = external_address::from_bytes(deserialize::deserialize_vector(&mut cursor, 32));
28+
let emitter_address = external_address::new(bytes32::from_bytes(deserialize::deserialize_vector(&mut cursor, 32)));
2829
let initial_sequence = deserialize::deserialize_u64(&mut cursor);
2930
cursor::destroy_empty(cursor);
3031
SetGovernanceDataSource {

target_chains/sui/contracts/sources/price_info.move

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ module pyth::price_info {
1313

1414
friend pyth::pyth;
1515

16-
/// Sui Object version of PriceInfo.
17-
/// Has a key and lives in global store.
16+
/// Sui object version of PriceInfo.
17+
/// Has a key ability, is unique for each price identifier, and lives in global store.
1818
struct PriceInfoObject has key, store {
1919
id: UID,
2020
price_info: PriceInfo

0 commit comments

Comments
 (0)