Skip to content

Commit b4e2712

Browse files
authored
feat(lazer): Update EVM Example and Test (#46)
* Update example evm and js * Not perfectly working test * Update JS to use real time and make tests pass * Change js sdk version usage * No change to js package json * Use main branch crosschain
1 parent ae783da commit b4e2712

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

lazer/evm/lib/pyth-crosschain

Submodule pyth-crosschain updated 496 files

lazer/evm/src/ExampleReceiver.sol

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ contract ExampleReceiver {
99
PythLazer pythLazer;
1010
uint64 public price;
1111
uint64 public timestamp;
12+
int16 public exponent;
13+
uint16 public publisher_count;
1214

1315
constructor(address pythLazerAddress) {
1416
pythLazer = PythLazer(pythLazerAddress);
@@ -43,7 +45,7 @@ contract ExampleReceiver {
4345
uint64 _price;
4446
(_price, pos) = PythLazerLib.parseFeedValueUint64(payload, pos);
4547
console.log("price %d", _price);
46-
if (feedId == 2 && _timestamp > timestamp) {
48+
if (feedId == 6 && _timestamp > timestamp) {
4749
price = _price;
4850
timestamp = _timestamp;
4951
}
@@ -55,6 +57,16 @@ contract ExampleReceiver {
5557
uint64 _price;
5658
(_price, pos) = PythLazerLib.parseFeedValueUint64(payload, pos);
5759
console.log("best ask price %d", _price);
60+
} else if (property == PythLazerLib.PriceFeedProperty.Exponent) {
61+
int16 _exponent;
62+
(_exponent, pos) = PythLazerLib.parseFeedValueInt16(payload, pos);
63+
console.log("exponent %d", _exponent);
64+
exponent = _exponent;
65+
} else if (property == PythLazerLib.PriceFeedProperty.PublisherCount) {
66+
uint16 _publisher_count;
67+
(_publisher_count, pos) = PythLazerLib.parseFeedValueUint16(payload, pos);
68+
console.log("publisher count %d", _publisher_count);
69+
publisher_count = _publisher_count;
5870
} else {
5971
revert("unknown property");
6072
}

lazer/evm/test/ExampleReceiver.t.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ contract ExampleReceiverTest is Test {
99
function setUp() public {}
1010

1111
function test_1() public {
12-
address trustedSigner = 0xEfEf56cD66896f6799A90A4e4d512C330c094e44;
12+
address trustedSigner = 0xb8d50f0bAE75BF6E03c104903d7C3aFc4a6596Da;
1313
console.log("trustedSigner %s", trustedSigner);
1414

1515
address lazer = makeAddr("lazer");
@@ -25,14 +25,16 @@ contract ExampleReceiverTest is Test {
2525

2626
ExampleReceiver receiver = new ExampleReceiver(address(pythLazer));
2727
bytes memory update =
28-
hex"2a22999a577d3cc0202197939d736bc0dcf71b9dde7b9470e4d16fa8e2120c0787a1c0d744d0c39cc372af4d1ecf2d09e84160ca905f3f597d20e2eec144a446a0459ad600001c93c7d3750006240af373971c01010000000201000000000005f5e100";
28+
hex"2a22999a9ee4e2a3df5affd0ad8c7c46c96d3b5ef197dd653bedd8f44a4b6b69b767fbc66341e80b80acb09ead98c60d169b9a99657ebada101f447378f227bffbc69d3d01003493c7d37500062cf28659c1e801010000000605000000000005f5e10002000000000000000001000000000000000003000104fff8";
2929
console.logBytes(update);
3030

3131
vm.prank(consumer);
3232
receiver.updatePrice{value: 5 * fee}(update);
3333

34+
assertEq(receiver.timestamp(), 1738270008001000);
3435
assertEq(receiver.price(), 100000000);
35-
assertEq(receiver.timestamp(), 1728479312975644);
36+
assertEq(receiver.exponent(), -8);
37+
assertEq(receiver.publisher_count(), 1);
3638

3739
assertEq(address(pythLazer).balance, fee);
3840
assertEq(address(receiver).balance, 0);

0 commit comments

Comments
 (0)