Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Remove underscore suffix from public variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnaguib committed Nov 28, 2018
1 parent fb9a7ae commit 3f46daf
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 65 deletions.
30 changes: 15 additions & 15 deletions contracts/MarketOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract MarketOracle is Ownable {
using SafeMath for uint256;

// Whitelist of sources
MarketSource[] public _whitelist;
MarketSource[] public whitelist;

event LogSourceAdded(MarketSource source);
event LogSourceRemoved(MarketSource source);
Expand All @@ -42,11 +42,11 @@ contract MarketOracle is Ownable {
uint256 partialVolume = 0;
bool isSourceFresh = false;

for (uint256 i = 0; i < _whitelist.length; i++) {
(isSourceFresh, partialRate, partialVolume) = _whitelist[i].getReport();
for (uint256 i = 0; i < whitelist.length; i++) {
(isSourceFresh, partialRate, partialVolume) = whitelist[i].getReport();

if (!isSourceFresh) {
emit LogSourceExpired(_whitelist[i]);
emit LogSourceExpired(whitelist[i]);
continue;
}

Expand All @@ -70,7 +70,7 @@ contract MarketOracle is Ownable {
external
onlyOwner
{
_whitelist.push(source);
whitelist.push(source);
emit LogSourceAdded(source);
}

Expand All @@ -82,8 +82,8 @@ contract MarketOracle is Ownable {
external
onlyOwner
{
for (uint256 i = 0; i < _whitelist.length; i++) {
if (_whitelist[i] == source) {
for (uint256 i = 0; i < whitelist.length; i++) {
if (whitelist[i] == source) {
removeSourceAtIndex(i);
break;
}
Expand All @@ -98,8 +98,8 @@ contract MarketOracle is Ownable {
external
{
uint256 i = 0;
while (i < _whitelist.length) {
if (isContractDestructed(_whitelist[i])) {
while (i < whitelist.length) {
if (isContractDestructed(whitelist[i])) {
removeSourceAtIndex(i);
} else {
i++;
Expand All @@ -115,7 +115,7 @@ contract MarketOracle is Ownable {
view
returns (uint256)
{
return _whitelist.length;
return whitelist.length;
}

/**
Expand All @@ -139,11 +139,11 @@ contract MarketOracle is Ownable {
function removeSourceAtIndex(uint256 index)
private
{
// assert(_whitelist.length > index);
emit LogSourceRemoved(_whitelist[index]);
if (index != _whitelist.length-1) {
_whitelist[index] = _whitelist[_whitelist.length-1];
// assert(whitelist.length > index);
emit LogSourceRemoved(whitelist[index]);
if (index != whitelist.length-1) {
whitelist[index] = whitelist[whitelist.length-1];
}
_whitelist.length--;
whitelist.length--;
}
}
12 changes: 6 additions & 6 deletions contracts/MarketSource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract MarketSource is Destructible {
);

// Name of the source reporting exchange rates
string public _name;
string public name;

// These are the three oracle values that are continuously reported.
// Smaller types are used here locally to save on storage gas.
Expand All @@ -30,11 +30,11 @@ contract MarketSource is Destructible {
uint64 private _timestampSec;

// The number of seconds after which the report must be deemed expired.
uint64 public _reportExpirationTimeSec;
uint64 public reportExpirationTimeSec;

constructor(string name, uint64 reportExpirationTimeSec) public {
_name = name;
_reportExpirationTimeSec = reportExpirationTimeSec;
constructor(string name_, uint64 reportExpirationTimeSec_) public {
name = name_;
reportExpirationTimeSec = reportExpirationTimeSec_;
}

/**
Expand Down Expand Up @@ -73,7 +73,7 @@ contract MarketSource is Destructible {
view
returns (bool, uint256, uint256)
{
bool isFresh = (uint256(_timestampSec).add(_reportExpirationTimeSec) > now);
bool isFresh = (uint256(_timestampSec).add(reportExpirationTimeSec) > now);
return (
isFresh,
uint256(_exchangeRate),
Expand Down
65 changes: 33 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"app-root-path": "^2.0.1",
"frg-ethereum-runners": "git+ssh://[email protected]/frgprotocol/frg-ethereum-runners.git#master",
"frg-ethereum-runners": "git+ssh://[email protected]/frgprotocol/frg-ethereum-runners.git",
"js-yaml": "^3.11.0",
"openzeppelin-solidity": "1.10.0",
"truffle": "^4.1.13"
Expand Down
14 changes: 7 additions & 7 deletions test/unit/market_oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract('MarketOracle:addSource', async function (accounts) {
expect(event.args.source).to.eq(source.address);
});
it('should add source to the whitelist', async function () {
expect(await oracle._whitelist.call(0)).to.eq(source.address);
expect(await oracle.whitelist.call(0)).to.eq(source.address);
(await oracle.whitelistSize.call()).should.be.bignumber.eq(1);
});
});
Expand Down Expand Up @@ -92,7 +92,7 @@ contract('MarketOracle:removeSource', async function (accounts) {
expect(event.args.source).to.eq(source.address);
});
it('should remove source from the whitelist', async function () {
expect(await oracle._whitelist.call(0)).to.eq(source2.address);
expect(await oracle.whitelist.call(0)).to.eq(source2.address);
(await oracle.whitelistSize.call()).should.be.bignumber.eq(1);
});
});
Expand All @@ -113,8 +113,8 @@ contract('MarketOracle:removeSource', async function (accounts) {
expect(logs).to.be.empty;
});
it('should NOT remove source any from the whitelist', async function () {
expect(await oracle._whitelist.call(0)).to.eq(source.address);
expect(await oracle._whitelist.call(1)).to.eq(source2.address);
expect(await oracle.whitelist.call(0)).to.eq(source.address);
expect(await oracle.whitelist.call(1)).to.eq(source2.address);
(await oracle.whitelistSize.call()).should.be.bignumber.eq(2);
});
});
Expand Down Expand Up @@ -249,7 +249,7 @@ contract('MarketOracle:removeDestructedSources', async function (accounts) {
});

it('should remove the dead source from the whitelist', async function () {
expect(await oracle._whitelist.call(0)).to.eq(source.address);
expect(await oracle.whitelist.call(0)).to.eq(source.address);
(await oracle.whitelistSize.call()).should.be.bignumber.eq(1);
});
});
Expand All @@ -270,8 +270,8 @@ contract('MarketOracle:removeDestructedSources', async function (accounts) {
expect(logs).to.be.empty;
});
it('should NOT remove any source from the whitelist', async function () {
expect(await oracle._whitelist.call(0)).to.eq(source.address);
expect(await oracle._whitelist.call(1)).to.eq(source2.address);
expect(await oracle.whitelist.call(0)).to.eq(source.address);
expect(await oracle.whitelist.call(1)).to.eq(source2.address);
(await oracle.whitelistSize.call()).should.be.bignumber.eq(2);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/market_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ contract('MarketSource:initialization', async function (accounts) {
});

it('should set the name', async function () {
expect(await source._name.call()).to.eq('GDAX');
expect(await source.name.call()).to.eq('GDAX');
});

it('should set the expiration time', async function () {
(await source._reportExpirationTimeSec.call()).should.be.bignumber.eq(600);
(await source.reportExpirationTimeSec.call()).should.be.bignumber.eq(600);
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/unit/market_source_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ contract('MarketSourceFactory', async function (accounts) {
it('should transfer ownership to sender', async function () {
const marketSource = MarketSource.at(sourceContractAddr);
expect(await marketSource.owner.call()).to.eq(A);
expect(await marketSource._name.call()).to.eq('GDAX');
(await marketSource._reportExpirationTimeSec.call()).should.be.bignumber.eq(3600);
expect(await marketSource.name.call()).to.eq('GDAX');
(await marketSource.reportExpirationTimeSec.call()).should.be.bignumber.eq(3600);
});
});
});

0 comments on commit 3f46daf

Please sign in to comment.