Skip to content

Commit 217118a

Browse files
committed
add test
1 parent 574a872 commit 217118a

File tree

2 files changed

+134
-1
lines changed

2 files changed

+134
-1
lines changed

target_chains/ton/contracts/contracts/Pyth.fc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
355355
.store_coins(excess)
356356
.store_uint(1, MSG_SERIALIZE_BITS)
357357
.store_ref(response.end_cell())
358-
359358
.end_cell(),
360359
0);
361360
}

target_chains/ton/contracts/tests/PythTest.spec.ts

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ describe("PythTest", () => {
106106

107107
let blockchain: Blockchain;
108108
let deployer: SandboxContract<TreasuryContract>;
109+
let mockDeployer: SandboxContract<TreasuryContract>;
109110
let pythTest: SandboxContract<PythTest>;
110111

111112
beforeEach(async () => {
112113
blockchain = await Blockchain.create();
113114
deployer = await blockchain.treasury("deployer");
115+
mockDeployer = await blockchain.treasury("mockDeployer");
114116
});
115117

116118
async function deployContract(
@@ -1508,4 +1510,136 @@ describe("PythTest", () => {
15081510
// Verify this is the end of the chain
15091511
expect(btcCs.remainingRefs).toBe(0);
15101512
});
1513+
1514+
it("should successfully parse price feed updates with a different target address", async () => {
1515+
await deployContract();
1516+
await updateGuardianSets(pythTest, deployer);
1517+
1518+
const sentValue = toNano("1");
1519+
const result = await pythTest.sendParsePriceFeedUpdates(
1520+
deployer.getSender(),
1521+
Buffer.from(HERMES_BTC_ETH_UPDATE, "hex"),
1522+
sentValue,
1523+
[BTC_PRICE_FEED_ID, ETH_PRICE_FEED_ID],
1524+
HERMES_BTC_PUBLISH_TIME,
1525+
HERMES_BTC_PUBLISH_TIME,
1526+
mockDeployer.address,
1527+
CUSTOM_PAYLOAD
1528+
);
1529+
1530+
// Verify transaction success and message count
1531+
expect(result.transactions).toHaveTransaction({
1532+
from: deployer.address,
1533+
to: pythTest.address,
1534+
success: true,
1535+
outMessagesCount: 1,
1536+
});
1537+
1538+
// Verify message success to target address
1539+
expect(result.transactions).toHaveTransaction({
1540+
from: pythTest.address,
1541+
to: mockDeployer.address,
1542+
success: true,
1543+
});
1544+
1545+
// Get the output message
1546+
const outMessage = result.transactions[1].outMessages.values()[0];
1547+
1548+
// Verify excess value is returned
1549+
expect(
1550+
(outMessage.info as CommonMessageInfoInternal).value.coins
1551+
).toBeGreaterThan(0);
1552+
1553+
const cs = outMessage.body.beginParse();
1554+
1555+
// Verify message header
1556+
const op = cs.loadUint(32);
1557+
expect(op).toBe(5); // OP_PARSE_PRICE_FEED_UPDATES
1558+
1559+
// Verify number of price feeds
1560+
const numPriceFeeds = cs.loadUint(8);
1561+
expect(numPriceFeeds).toBe(2); // We expect BTC and ETH price feeds
1562+
1563+
cs.loadRef(); // Skip price feeds
1564+
1565+
// Verify sender address
1566+
const senderAddress = cs.loadAddress();
1567+
expect(senderAddress?.toString()).toBe(deployer.address.toString());
1568+
1569+
// Verify custom payload
1570+
const customPayloadCell = cs.loadRef();
1571+
const customPayloadSlice = customPayloadCell.beginParse();
1572+
const receivedPayload = Buffer.from(
1573+
customPayloadSlice.loadBuffer(CUSTOM_PAYLOAD.length)
1574+
);
1575+
expect(receivedPayload.toString("hex")).toBe(
1576+
CUSTOM_PAYLOAD.toString("hex")
1577+
);
1578+
});
1579+
1580+
it("should successfully parse unique price feed updates with a different target address", async () => {
1581+
await deployContract();
1582+
await updateGuardianSets(pythTest, deployer);
1583+
1584+
const sentValue = toNano("1");
1585+
const result = await pythTest.sendParseUniquePriceFeedUpdates(
1586+
deployer.getSender(),
1587+
Buffer.from(HERMES_BTC_ETH_UNIQUE_UPDATE, "hex"),
1588+
sentValue,
1589+
[BTC_PRICE_FEED_ID, ETH_PRICE_FEED_ID],
1590+
HERMES_BTC_PUBLISH_TIME,
1591+
60,
1592+
mockDeployer.address,
1593+
CUSTOM_PAYLOAD
1594+
);
1595+
1596+
// Verify transaction success and message count
1597+
expect(result.transactions).toHaveTransaction({
1598+
from: deployer.address,
1599+
to: pythTest.address,
1600+
success: true,
1601+
outMessagesCount: 1,
1602+
});
1603+
1604+
// Verify message success to target address
1605+
expect(result.transactions).toHaveTransaction({
1606+
from: pythTest.address,
1607+
to: mockDeployer.address,
1608+
success: true,
1609+
});
1610+
1611+
// Get the output message
1612+
const outMessage = result.transactions[1].outMessages.values()[0];
1613+
1614+
// Verify excess value is returned
1615+
expect(
1616+
(outMessage.info as CommonMessageInfoInternal).value.coins
1617+
).toBeGreaterThan(0);
1618+
1619+
const cs = outMessage.body.beginParse();
1620+
1621+
// Verify message header
1622+
const op = cs.loadUint(32);
1623+
expect(op).toBe(6); // OP_PARSE_UNIQUE_PRICE_FEED_UPDATES
1624+
1625+
// Verify number of price feeds
1626+
const numPriceFeeds = cs.loadUint(8);
1627+
expect(numPriceFeeds).toBe(2); // We expect BTC and ETH price feeds
1628+
1629+
cs.loadRef(); // Skip price feeds
1630+
1631+
// Verify sender address
1632+
const senderAddress = cs.loadAddress();
1633+
expect(senderAddress?.toString()).toBe(deployer.address.toString());
1634+
1635+
// Verify custom payload
1636+
const customPayloadCell = cs.loadRef();
1637+
const customPayloadSlice = customPayloadCell.beginParse();
1638+
const receivedPayload = Buffer.from(
1639+
customPayloadSlice.loadBuffer(CUSTOM_PAYLOAD.length)
1640+
);
1641+
expect(receivedPayload.toString("hex")).toBe(
1642+
CUSTOM_PAYLOAD.toString("hex")
1643+
);
1644+
});
15111645
});

0 commit comments

Comments
 (0)