Skip to content

Commit

Permalink
feat: removing observationsData from ObservationsAdded event
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Aug 14, 2024
1 parent 72c3924 commit f3a7d46
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
8 changes: 4 additions & 4 deletions solidity/contracts/DataReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {IDataReceiver, IOracleFactory, IOracleSidechain, IBridgeReceiverAdapter}
import {console} from 'hardhat/console.sol';

/** TODO:
* - [ ] cache observations
* - [ ] remove ObservationsData from event
* - [x] cache observations
* - [x] remove ObservationsData from event
* - [ ] add ObservationsCached event
* - [ ] remove console logs
*/
Expand Down Expand Up @@ -59,7 +59,7 @@ contract DataReceiver is IDataReceiver, Governable {
console.log('writing', _poolNonce);
if (_oracle.write(_observationsData, _poolNonce)) {
console.log('writed', _poolNonce);
emit ObservationsAdded(_poolSalt, _poolNonce, _observationsData, msg.sender);
emit ObservationsAdded(_poolSalt, _poolNonce, msg.sender);
} else {
console.log('caching', _poolNonce);
// Query pool's current nonce
Expand All @@ -81,7 +81,7 @@ contract DataReceiver is IDataReceiver, Governable {
// Since observation nonce == oracle nonce, we can safely write the observations
console.log('writing', _currentNonce);
_oracle.write(_cachedObservations, _currentNonce);
emit ObservationsAdded(_poolSalt, _currentNonce, _cachedObservations, msg.sender);
emit ObservationsAdded(_poolSalt, _currentNonce, msg.sender);
// Clear out the written observations
delete cachedObservations[_poolSalt][_currentNonce];
_currentNonce++;
Expand Down
8 changes: 1 addition & 7 deletions solidity/interfaces/IDataReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,8 @@ interface IDataReceiver is IGovernable {
/// @notice Emitted when a broadcast observation is succesfully processed
/// @param _poolSalt Identifier of the pool to fetch
/// @return _poolNonce Nonce of the observation broadcast
/// @return _observationsData Array of tuples containing the dataset
/// @return _receiverAdapter Handler of the broadcast
event ObservationsAdded(
bytes32 indexed _poolSalt,
uint24 _poolNonce,
IOracleSidechain.ObservationData[] _observationsData,
address _receiverAdapter
);
event ObservationsAdded(bytes32 indexed _poolSalt, uint24 _poolNonce, address _receiverAdapter);

/// @notice Emitted when a new adapter whitelisting rule is set
/// @param _adapter Address of the adapter
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/oracle-sidechain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ describe('@skip-on-coverage OracleSidechain.sol', () => {
const tx4 = await allowedDataReceiver.internalAddObservations(obs4, salt, 4); // should include 3

// NOTE: chai is failing to compare the emitted struct[], so we are not checking the arguments
await expect(tx1).to.emit(allowedDataReceiver, 'ObservationsAdded'); //.withArgs(salt, 1, obs1, deployer);
await expect(tx1).to.emit(allowedDataReceiver, 'ObservationsAdded').withArgs(salt, 1, deployer.address);
// TODO: await expect(tx2).to.emit(allowedDataReceiver, 'ObservationsCached');
await expect(tx2).not.to.emit(allowedDataReceiver, 'ObservationsAdded');
await expect(tx3).to.emit(allowedDataReceiver, 'ObservationsAdded'); //.withArgs(salt, 2, obs2, deployer);
await expect(tx4).to.emit(allowedDataReceiver, 'ObservationsAdded'); //.withArgs(salt, 3, obs3, deployer);
// await expect(tx4).to.emit(allowedDataReceiver, 'ObservationsAdded').withArgs(salt, 4, obs4, deployer);
await expect(tx3).to.emit(allowedDataReceiver, 'ObservationsAdded').withArgs(salt, 2, deployer.address);
await expect(tx4).to.emit(allowedDataReceiver, 'ObservationsAdded').withArgs(salt, 3, deployer.address);
await expect(tx4).to.emit(allowedDataReceiver, 'ObservationsAdded').withArgs(salt, 4, deployer.address);
});
});
});
16 changes: 9 additions & 7 deletions test/unit/DataReceiver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import chai, { expect } from 'chai';

chai.use(smock.matchers);

describe('DataReceiver.sol', () => {
describe.only('DataReceiver.sol', () => {
let governor: SignerWithAddress;
let fakeAdapter: SignerWithAddress;
let randomAdapter: SignerWithAddress;
Expand Down Expand Up @@ -100,12 +100,10 @@ describe('DataReceiver.sol', () => {
let eventAdapter = await readArgFromEvent(tx, 'ObservationsAdded', '_receiverAdapter');
let eventSalt = await readArgFromEvent(tx, 'ObservationsAdded', '_poolSalt');
let eventNonce = await readArgFromEvent(tx, 'ObservationsAdded', '_poolNonce');
let eventObservationsData = await readArgFromEvent(tx, 'ObservationsAdded', '_observationsData');

expect(eventAdapter).to.eq(fakeAdapter.address);
expect(eventSalt).to.eq(randomSalt);
expect(eventNonce).to.eq(randomNonce);
expect(eventObservationsData).to.eql(observationsData);
});
});

Expand All @@ -132,10 +130,12 @@ describe('DataReceiver.sol', () => {
it('should emit ObservationsAdded', async () => {
tx = await dataReceiver.connect(fakeAdapter).addObservations(observationsData, randomSalt, randomNonce);
let eventAdapter = await readArgFromEvent(tx, 'ObservationsAdded', '_receiverAdapter');
let eventObservationsData = await readArgFromEvent(tx, 'ObservationsAdded', '_observationsData');
let eventSalt = await readArgFromEvent(tx, 'ObservationsAdded', '_poolSalt');
let eventNonce = await readArgFromEvent(tx, 'ObservationsAdded', '_poolNonce');

expect(eventAdapter).to.eq(fakeAdapter.address);
expect(eventObservationsData).to.eql(observationsData);
expect(eventSalt).to.eq(randomSalt);
expect(eventNonce).to.eq(randomNonce);
});
});

Expand All @@ -161,10 +161,12 @@ describe('DataReceiver.sol', () => {
it('should emit ObservationsAdded', async () => {
tx = await dataReceiver.connect(fakeAdapter).addObservations(observationsData, randomSalt, randomNonce);
let eventAdapter = await readArgFromEvent(tx, 'ObservationsAdded', '_receiverAdapter');
let eventObservationsData = await readArgFromEvent(tx, 'ObservationsAdded', '_observationsData');
let eventSalt = await readArgFromEvent(tx, 'ObservationsAdded', '_poolSalt');
let eventNonce = await readArgFromEvent(tx, 'ObservationsAdded', '_poolNonce');

expect(eventAdapter).to.eq(fakeAdapter.address);
expect(eventObservationsData).to.eql(observationsData);
expect(eventSalt).to.eq(randomSalt);
expect(eventNonce).to.eq(randomNonce);
});
});
});
Expand Down

0 comments on commit f3a7d46

Please sign in to comment.