Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel committed Sep 12, 2024
1 parent ccd685c commit c2d456b
Showing 1 changed file with 83 additions and 43 deletions.
126 changes: 83 additions & 43 deletions target_chains/ton/contracts/tests/PythTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,53 +384,87 @@ describe("PythTest", () => {
).rejects.toThrow("Unable to execute get method. Got exit_code: 1019"); // ERROR_PRICE_FEED_NOT_FOUND = 1019
});

it("should return the correct chain ID", async () => {
it("should correctly get chain ID", async () => {
await deployContract();

const result = await pythTest.getChainId();
expect(result).toEqual(1);
});

it("should return the correct last executed governance sequence", async () => {
await deployContract();
it("should correctly get last executed governance sequence", async () => {
await deployContract(
BTC_PRICE_FEED_ID,
TIME_PERIOD,
PRICE,
EMA_PRICE,
SINGLE_UPDATE_FEE,
DATA_SOURCES,
0,
[TEST_GUARDIAN_ADDRESS1],
60051,
1,
"0000000000000000000000000000000000000000000000000000000000000004",
TEST_GOVERNANCE_DATA_SOURCES[0]
);

const result = await pythTest.getLastExecutedGovernanceSequence();
expect(result).toEqual(0); // Initial value should be 0
// Check initial value
let result = await pythTest.getLastExecutedGovernanceSequence();
expect(result).toEqual(0);

// Execute a governance action (e.g., set fee)
await pythTest.sendExecuteGovernanceAction(
deployer.getSender(),
Buffer.from(PYTH_SET_FEE, "hex")
);

// TODO: add more tests for other governance sequences
// Check that the sequence has increased
result = await pythTest.getLastExecutedGovernanceSequence();
expect(result).toEqual(1);
});

it("should return the correct governance data source index", async () => {
await deployContract();
it("should correctly get governance data source index", async () => {
// Deploy contract with initial governance data source
await deployContract(
BTC_PRICE_FEED_ID,
TIME_PERIOD,
PRICE,
EMA_PRICE,
SINGLE_UPDATE_FEE,
DATA_SOURCES,
0,
[TEST_GUARDIAN_ADDRESS1],
60051,
1,
"0000000000000000000000000000000000000000000000000000000000000004",
TEST_GOVERNANCE_DATA_SOURCES[0]
);

const result = await pythTest.getGovernanceDataSourceIndex();
expect(result).toEqual(0); // Initial value should be 0
// Check initial value
let result = await pythTest.getGovernanceDataSourceIndex();
expect(result).toEqual(0);

// TODO: add more tests for other governance data source index
// Execute governance action to change data source
await pythTest.sendExecuteGovernanceAction(
deployer.getSender(),
Buffer.from(PYTH_AUTHORIZE_GOVERNANCE_DATA_SOURCE_TRANSFER, "hex")
);

// Check that the index has increased
result = await pythTest.getGovernanceDataSourceIndex();
expect(result).toEqual(1);
});

it("should return an empty cell for governance data source", async () => {
it("should correctly get governance data source", async () => {
// Deploy contract without initial governance data source
await deployContract();

const result = await pythTest.getGovernanceDataSource();
// assert that the result is an empty cell initally
// Check initial value (should be empty)
let result = await pythTest.getGovernanceDataSource();
expect(result).toBeDefined();
expect(result.bits.length).toBe(0);
expect(result.refs.length).toBe(0);

// TODO: add more tests for other governance data source
});

it("should correctly get single update fee", async () => {
await deployContract();

// Get the initial fee
const result = await pythTest.getSingleUpdateFee();

expect(result).toBe(SINGLE_UPDATE_FEE);
});

it("should execute set fee governance instruction", async () => {
// Deploy contract with initial governance data source
await deployContract(
BTC_PRICE_FEED_ID,
TIME_PERIOD,
Expand All @@ -440,33 +474,39 @@ describe("PythTest", () => {
DATA_SOURCES,
0,
[TEST_GUARDIAN_ADDRESS1],
60051, // CHAIN_ID of starknet since we are using the test payload for starknet
60051,
1,
"0000000000000000000000000000000000000000000000000000000000000004",
TEST_GOVERNANCE_DATA_SOURCES[0]
);

// Get the initial fee
const initialFee = await pythTest.getSingleUpdateFee();
expect(initialFee).toEqual(SINGLE_UPDATE_FEE);
// Check that the governance data source is set
result = await pythTest.getGovernanceDataSource();
let dataSource = parseDataSource(result);
expect(dataSource).toEqual(TEST_GOVERNANCE_DATA_SOURCES[0]);

// Execute the governance action
const result = await pythTest.sendExecuteGovernanceAction(
// Execute governance action to change data source
await pythTest.sendExecuteGovernanceAction(
deployer.getSender(),
Buffer.from(PYTH_SET_FEE, "hex")
Buffer.from(PYTH_AUTHORIZE_GOVERNANCE_DATA_SOURCE_TRANSFER, "hex")
);
expect(result.transactions).toHaveTransaction({
from: deployer.address,
to: pythTest.address,
success: true,
});

// Get the new fee
const newFee = await pythTest.getSingleUpdateFee();
expect(newFee).toEqual(4200);
// Check that the data source has changed
result = await pythTest.getGovernanceDataSource();
dataSource = parseDataSource(result);
expect(dataSource).toEqual(TEST_GOVERNANCE_DATA_SOURCES[1]);
});

it("should execute set data sources governance instruction", async () => {
it("should correctly get single update fee", async () => {
await deployContract();

// Get the initial fee
const result = await pythTest.getSingleUpdateFee();

expect(result).toBe(SINGLE_UPDATE_FEE);
});

it("should execute set fee governance instruction", async () => {
await deployContract(
BTC_PRICE_FEED_ID,
TIME_PERIOD,
Expand Down

0 comments on commit c2d456b

Please sign in to comment.