20
20
from contextlib import contextmanager
21
21
import shutil
22
22
from solana .keypair import Keypair
23
- from solders .system_program import ID as SYSTEM_PROGRAM_ID
24
23
from solana .rpc .async_api import AsyncClient
25
24
from solana .rpc import commitment
26
- from solana .transaction import AccountMeta , Transaction , TransactionInstruction
25
+ from solana .transaction import AccountMeta , Transaction
27
26
from anchorpy import Provider , Wallet
28
- from construct import Bytes , Int32sl , Int32ul , Struct
29
27
from solana .publickey import PublicKey
30
28
from message_buffer_client_codegen .instructions import initialize , set_allowed_programs , create_buffer
31
29
from message_buffer_client_codegen .accounts .message_buffer import MessageBuffer
@@ -359,21 +357,6 @@ def agent_publish_keypair(self, agent_keystore_path, sync_accounts):
359
357
LOGGER .debug (f"Publisher { address .stdout .strip ()} balance: { balance .stdout .strip ()} " )
360
358
time .sleep (8 )
361
359
362
- @pytest .fixture
363
- def agent_keystore (self , agent_keystore_path , agent_publish_keypair ):
364
- self .run (
365
- f"../scripts/init_key_store.sh localnet { agent_keystore_path } " )
366
-
367
- if USE_ACCUMULATOR :
368
- path = os .path .join (agent_keystore_path , "accumulator_program_key.json" )
369
-
370
- with open (path , 'w' ) as f :
371
- f .write (MESSAGE_BUFFER_PROGRAM )
372
-
373
- if os .path .exists ("keystore" ):
374
- os .remove ("keystore" )
375
- os .symlink (agent_keystore_path , "keystore" )
376
-
377
360
@pytest_asyncio .fixture
378
361
async def initialize_message_buffer_program (self , funding_keypair , sync_key_path , sync_accounts ):
379
362
@@ -429,18 +412,15 @@ async def initialize_message_buffer_program(self, funding_keypair, sync_key_path
429
412
await provider .send (tx , [parsed_funding_keypair ])
430
413
431
414
@pytest .fixture
432
- def agent_config (self , agent_keystore , agent_keystore_path , tmp_path ):
415
+ def agent_config (self , agent_keystore_path , agent_publish_keypair , tmp_path ):
433
416
with open ("agent_conf.toml" ) as config_file :
434
417
agent_config = config_file .read ()
435
418
436
419
publish_keypair_path = os .path .join (agent_keystore_path , "publish_key_pair.json" )
437
420
438
- mapping_keypair = Keypair .from_secret_key (MAPPING_KEYPAIR )
439
-
440
421
agent_config += f"""
441
422
key_store.publish_keypair_path = "{ publish_keypair_path } "
442
423
key_store.program_key = "{ ORACLE_PROGRAM } "
443
- key_store.mapping_key = "{ mapping_keypair .public_key } "
444
424
"""
445
425
446
426
# Add accumulator setting if option is enabled
@@ -457,32 +437,7 @@ def agent_config(self, agent_keystore, agent_keystore_path, tmp_path):
457
437
return path
458
438
459
439
@pytest .fixture
460
- def agent_legacy_config (self , agent_keystore , agent_keystore_path , tmp_path ):
461
- """
462
- Prepares a legacy v1.x.x config for testing agent-migrate-config
463
- """
464
- with open ("agent_conf.toml" ) as config_file :
465
- agent_config = config_file .read ()
466
-
467
- agent_config += f'\n key_store.root_path = "{ agent_keystore_path } "'
468
-
469
- if USE_ACCUMULATOR :
470
- # Add accumulator setting to verify that it is inlined as well
471
- agent_config += f'\n key_store.accumulator_key_path = "accumulator_program_key.json"'
472
-
473
- LOGGER .debug (f"Built legacy agent config:\n { agent_config } " )
474
-
475
- path = os .path .join (tmp_path , "agent_conf_legacy.toml" )
476
-
477
- with open (path , 'w' ) as f :
478
- f .write (agent_config )
479
-
480
- return path
481
-
482
-
483
-
484
- @pytest .fixture
485
- def agent (self , sync_accounts , agent_keystore , tmp_path , initialize_message_buffer_program , agent_config ):
440
+ def agent (self , sync_accounts , agent_keystore_path , agent_publish_keypair , tmp_path , initialize_message_buffer_program , agent_config ):
486
441
LOGGER .debug ("Building agent binary" )
487
442
self .run ("cargo build --release --bin agent" )
488
443
@@ -496,7 +451,7 @@ def agent(self, sync_accounts, agent_keystore, tmp_path, initialize_message_buff
496
451
yield
497
452
498
453
@pytest .fixture
499
- def agent_hotload (self , sync_accounts , agent_keystore , agent_keystore_path , tmp_path , initialize_message_buffer_program , agent_config ):
454
+ def agent_hotload (self , sync_accounts , agent_keystore_path , tmp_path , initialize_message_buffer_program , agent_config ):
500
455
"""
501
456
Spawns an agent without a publish keypair, used for keypair hotloading testing
502
457
"""
@@ -560,11 +515,11 @@ async def test_update_price_simple(self, client: PythAgentClient):
560
515
561
516
# Send an "update_price" request
562
517
await client .update_price (price_account , 42 , 2 , "trading" )
563
- time .sleep (2 )
518
+ time .sleep (5 )
564
519
565
520
# Send another "update_price" request to trigger aggregation
566
521
await client .update_price (price_account , 81 , 1 , "trading" )
567
- time .sleep (2 )
522
+ time .sleep (5 )
568
523
569
524
# Confirm that the price account has been updated with the values from the first "update_price" request
570
525
final_product_state = await client .get_product (product_account )
@@ -726,44 +681,6 @@ async def test_publish_forever(self, client: PythAgentClient, tmp_path):
726
681
await client .update_price (price_account , 47 , 2 , "trading" )
727
682
time .sleep (1 )
728
683
729
- @pytest .mark .asyncio
730
- async def test_agent_migrate_config (self ,
731
- agent_keystore ,
732
- agent_legacy_config ,
733
- agent_migrate_config_binary ,
734
- client_no_spawn : PythAgentClient ,
735
- initialize_message_buffer_program ,
736
- sync_accounts ,
737
- tmp_path ,
738
- ):
739
- os .environ ["RUST_BACKTRACE" ] = "full"
740
- os .environ ["RUST_LOG" ] = "debug"
741
-
742
- # Migrator must run successfully (run() raises on error)
743
- new_config = self .run (f"{ agent_migrate_config_binary } -c { agent_legacy_config } " ).stdout .strip ()
744
-
745
- LOGGER .debug (f"Successfully migrated legacy config to:\n { new_config } " )
746
-
747
- # Overwrite legacy config with the migrated version.
748
- #
749
- # NOTE: assumes 'w' erases the file before access)
750
- with open (agent_legacy_config , 'w' ) as f :
751
- f .write (new_config )
752
- f .flush ()
753
-
754
- self .run ("cargo build --release --bin agent" )
755
-
756
- log_dir = os .path .join (tmp_path , "agent_logs" )
757
-
758
- # We start the agent manually to pass it the updated legacy config
759
- with self .spawn (f"../target/release/agent --config { agent_legacy_config } " , log_dir = log_dir ):
760
- time .sleep (3 )
761
- await client_no_spawn .connect ()
762
-
763
- # Continue with the simple test case, which must succeed
764
- await self .test_update_price_simple (client_no_spawn )
765
- await client_no_spawn .close ()
766
-
767
684
@pytest .mark .asyncio
768
685
async def test_agent_respects_market_hours (self , client : PythAgentClient ):
769
686
'''
@@ -784,13 +701,13 @@ async def test_agent_respects_market_hours(self, client: PythAgentClient):
784
701
785
702
# Send an "update_price" request
786
703
await client .update_price (price_account , 42 , 2 , "trading" )
787
- time .sleep (2 )
704
+ time .sleep (5 )
788
705
789
706
# Send another update_price request to "trigger" aggregation
790
707
# (aggregation would happen if market hours were to fail, but
791
708
# we want to catch that happening if there's a problem)
792
709
await client .update_price (price_account , 81 , 1 , "trading" )
793
- time .sleep (2 )
710
+ time .sleep (5 )
794
711
795
712
# Confirm that the price account has not been updated
796
713
final_product_state = await client .get_product (product_account )
@@ -819,13 +736,13 @@ async def test_agent_respects_holiday_hours(self, client: PythAgentClient):
819
736
820
737
# Send an "update_price" request
821
738
await client .update_price (price_account , 42 , 2 , "trading" )
822
- time .sleep (2 )
739
+ time .sleep (5 )
823
740
824
741
# Send another update_price request to "trigger" aggregation
825
742
# (aggregation would happen if market hours were to fail, but
826
743
# we want to catch that happening if there's a problem)
827
744
await client .update_price (price_account , 81 , 1 , "trading" )
828
- time .sleep (2 )
745
+ time .sleep (5 )
829
746
830
747
# Confirm that the price account has not been updated
831
748
final_product_state = await client .get_product (product_account )
@@ -861,7 +778,7 @@ async def test_agent_respects_publish_interval(self, client: PythAgentClient):
861
778
# (aggregation would happen if publish interval were to fail, but
862
779
# we want to catch that happening if there's a problem)
863
780
await client .update_price (price_account , 81 , 1 , "trading" )
864
- time .sleep (2 )
781
+ time .sleep (5 )
865
782
866
783
# Confirm that the price account has not been updated
867
784
final_product_state = await client .get_product (product_account )
@@ -875,7 +792,7 @@ async def test_agent_respects_publish_interval(self, client: PythAgentClient):
875
792
# Send another update_price request to "trigger" aggregation
876
793
# Now it is after the publish interval, so the price should be updated
877
794
await client .update_price (price_account , 81 , 1 , "trading" )
878
- time .sleep (2 )
795
+ time .sleep (5 )
879
796
880
797
# Confirm that the price account has been updated
881
798
final_product_state = await client .get_product (product_account )
0 commit comments