-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accumulator Support and Integration Testing (#62)
* adding stuff * add accumulator thing * tests: New oracle.so, add accumulator *.so, gen accumulator key * exporter: add transaction statuses logging * uh oh * stuff * update oracle * Update oracle.so, re-enable pub tx failure, more updates in tests * aggregate now updates * CPI is invoked * tests: fix wrong *.so for accumulator, bypassed checks in binaries * integration_tests: WIP accumulator initialize() call * update stuff * agent: oracle auth, tests: regen client, setup auth, new oracle.so * add anchorpy * it works * stuff * exporter: re-enable preflight, tests: hardcoding my thing this time! * Clean integration tests, new accumulator address, agent logging * exporter.rs: restore rpc calls to their former infallible glory * exporter: fix missing UPDATE_PRICE_NO_FAIL_ON_ERROR * test_integration.py: bring back solana logs * message_buffer -> message_buffer_client_codegen * move prebuilt artifacts to `program-binaries`, add md5 verification * README.md: replace other README with testing section, config docs * exporter: Remove code comment, oracle PDA log statement * integration-tests/pyproject.toml: Point at the root readme --------- Co-authored-by: Jayant Krishnamurthy <[email protected]>
- Loading branch information
1 parent
c0a3cd1
commit 77a858c
Showing
34 changed files
with
2,873 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
b213ae5b2a4137238c47bdc5951fc95d integration-tests/program-binaries/message_buffer_idl.json | ||
1d5b5e43be31e10f6e747b20ef77f4e9 integration-tests/program-binaries/message_buffer.so | ||
7c2782f6f58e9c91a95ce7c310a47927 integration-tests/program-binaries/oracle.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[metrics_server] | ||
bind_address="0.0.0.0:8888" | ||
|
||
[primary_network] | ||
key_store.root_path = "keystore" | ||
oracle.poll_interval_duration = "1s" | ||
exporter.transaction_monitor.poll_interval_duration = "1s" | ||
|
||
[metrics_server] | ||
bind_address="0.0.0.0:8888" |
Empty file.
2 changes: 2 additions & 0 deletions
2
integration-tests/message_buffer_client_codegen/accounts/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .message_buffer import MessageBuffer, MessageBufferJSON | ||
from .whitelist import Whitelist, WhitelistJSON |
99 changes: 99 additions & 0 deletions
99
integration-tests/message_buffer_client_codegen/accounts/message_buffer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import typing | ||
from dataclasses import dataclass | ||
from solana.publickey import PublicKey | ||
from solana.rpc.async_api import AsyncClient | ||
from solana.rpc.commitment import Commitment | ||
import borsh_construct as borsh | ||
from anchorpy.coder.accounts import ACCOUNT_DISCRIMINATOR_SIZE | ||
from anchorpy.error import AccountInvalidDiscriminator | ||
from anchorpy.utils.rpc import get_multiple_accounts | ||
from ..program_id import PROGRAM_ID | ||
|
||
|
||
class MessageBufferJSON(typing.TypedDict): | ||
bump: int | ||
version: int | ||
header_len: int | ||
end_offsets: list[int] | ||
|
||
|
||
@dataclass | ||
class MessageBuffer: | ||
discriminator: typing.ClassVar = b"\x19\xf4\x03\x05\xe1\xa5\x1d\xfa" | ||
layout: typing.ClassVar = borsh.CStruct( | ||
"bump" / borsh.U8, | ||
"version" / borsh.U8, | ||
"header_len" / borsh.U16, | ||
"end_offsets" / borsh.U16[255], | ||
) | ||
bump: int | ||
version: int | ||
header_len: int | ||
end_offsets: list[int] | ||
|
||
@classmethod | ||
async def fetch( | ||
cls, | ||
conn: AsyncClient, | ||
address: PublicKey, | ||
commitment: typing.Optional[Commitment] = None, | ||
program_id: PublicKey = PROGRAM_ID, | ||
) -> typing.Optional["MessageBuffer"]: | ||
resp = await conn.get_account_info(address, commitment=commitment) | ||
info = resp.value | ||
if info is None: | ||
return None | ||
if info.owner != program_id.to_solders(): | ||
raise ValueError("Account does not belong to this program") | ||
bytes_data = info.data | ||
return cls.decode(bytes_data) | ||
|
||
@classmethod | ||
async def fetch_multiple( | ||
cls, | ||
conn: AsyncClient, | ||
addresses: list[PublicKey], | ||
commitment: typing.Optional[Commitment] = None, | ||
program_id: PublicKey = PROGRAM_ID, | ||
) -> typing.List[typing.Optional["MessageBuffer"]]: | ||
infos = await get_multiple_accounts(conn, addresses, commitment=commitment) | ||
res: typing.List[typing.Optional["MessageBuffer"]] = [] | ||
for info in infos: | ||
if info is None: | ||
res.append(None) | ||
continue | ||
if info.account.owner != program_id: | ||
raise ValueError("Account does not belong to this program") | ||
res.append(cls.decode(info.account.data)) | ||
return res | ||
|
||
@classmethod | ||
def decode(cls, data: bytes) -> "MessageBuffer": | ||
if data[:ACCOUNT_DISCRIMINATOR_SIZE] != cls.discriminator: | ||
raise AccountInvalidDiscriminator( | ||
"The discriminator for this account is invalid" | ||
) | ||
dec = MessageBuffer.layout.parse(data[ACCOUNT_DISCRIMINATOR_SIZE:]) | ||
return cls( | ||
bump=dec.bump, | ||
version=dec.version, | ||
header_len=dec.header_len, | ||
end_offsets=dec.end_offsets, | ||
) | ||
|
||
def to_json(self) -> MessageBufferJSON: | ||
return { | ||
"bump": self.bump, | ||
"version": self.version, | ||
"header_len": self.header_len, | ||
"end_offsets": self.end_offsets, | ||
} | ||
|
||
@classmethod | ||
def from_json(cls, obj: MessageBufferJSON) -> "MessageBuffer": | ||
return cls( | ||
bump=obj["bump"], | ||
version=obj["version"], | ||
header_len=obj["header_len"], | ||
end_offsets=obj["end_offsets"], | ||
) |
Oops, something went wrong.