6-PYTHON-API: fix test for creating aggregator

This commit is contained in:
Albert Hermida 2022-06-07 14:54:49 -04:00
parent a188b86170
commit a3a800876f
2 changed files with 12 additions and 14 deletions

View File

@ -14,6 +14,7 @@ from switchboardpy.program import ProgramStateAccount
from switchboardpy.common import AccountParams
from switchboardpy.oraclequeue import OracleQueueAccount
from .generated.accounts import OracleAccountData
# Parameters for an OracleInit request
@dataclass
@ -85,9 +86,8 @@ class OracleAccount:
AccountInvalidDiscriminator: If the discriminator doesn't match the IDL.
"""
async def load_data(self):
oracle = await self.program.account["OracleAccountData"].fetch(self.public_key)
oracle.ebuf = None
return oracle
return await OracleAccountData.fetch(self.program.provider.connection, self.public_key)
"""
Loads a OracleAccount from the expected PDA seed format

View File

@ -37,37 +37,36 @@ class SwitchboardProgram(object):
async def test_load_data():
async with SwitchboardProgram() as program:
agg = AggregatorAccount(AccountParams(program=program, public_key=PublicKey("88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz")))
agg = AggregatorAccount(AccountParams(program=program, public_key=PublicKey("HMtDNnoCPD6NQRCE2uScEWSvwaZY3hWixCK12TKNtGpc")))
# getting aggregator data
data = await agg.load_data()
assert data.min_oracle_results == 3
assert data.oracle_request_batch_size == 6
assert data.min_job_results == 2
assert data.min_oracle_results == 2
assert data.oracle_request_batch_size == 3
assert data.min_job_results == 1
print(data)
@mark.asyncio
async def test_get_latest_value():
async with SwitchboardProgram() as program:
agg = AggregatorAccount(AccountParams(program=program, public_key=PublicKey("88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz")))
agg = AggregatorAccount(AccountParams(program=program, public_key=PublicKey("HMtDNnoCPD6NQRCE2uScEWSvwaZY3hWixCK12TKNtGpc")))
# getting most recent value
val = await agg.get_latest_value()
assert Decimal('180.12115') == val
assert Decimal('39.792') == val
print('LATEST VALUE:')
print(val)
@mark.asyncio
async def test_get_latest_value():
async def test_get_latest_timestamp():
async with SwitchboardProgram() as program:
agg = AggregatorAccount(AccountParams(program=program, public_key=PublicKey("88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz")))
agg = AggregatorAccount(AccountParams(program=program, public_key=PublicKey("HMtDNnoCPD6NQRCE2uScEWSvwaZY3hWixCK12TKNtGpc")))
# getting most recent value
val = await agg.get_latest_feed_timestamp()
assert Decimal('1639722030') == val
assert Decimal('1654626799') == val
print('LATEST TIMESTAMP:')
print(val)
@ -87,6 +86,5 @@ async def test_create():
public_key=PublicKey("F8ce7MsckeZAbAGmxjJNetxYXQa9mKr9nnrC3qKubyYy")
)
),
start_after=0,
)
)