Skip to content

Commit

Permalink
add setters
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAndell committed May 20, 2024
1 parent 4675b3e commit 683868e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package icon.inflation.score.pol;

import static icon.inflation.score.util.Checks.onlyOwner;
import static icon.inflation.score.util.Constants.EXA;

import java.math.BigInteger;

import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;

import icon.inflation.score.structs.LiquidityDistribution;
import icon.inflation.score.util.DBUtils;
import score.Context;
import score.Address;
import score.ArrayDB;
import score.Context;
import score.VarDB;
import score.Address;
import score.annotation.External;
import score.annotation.Payable;

import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;
import com.eclipsesource.json.JsonArray;

import static icon.inflation.score.util.Constants.EXA;
import static icon.inflation.score.util.Checks.onlyOwner;

public class ProofOfLiquidity {

public static final ArrayDB<LiquidityDistribution> distribution = Context.newArrayDB("DISTRIBUTIONS", LiquidityDistribution.class);
Expand All @@ -42,6 +42,42 @@ public String name() {
return NAME;
}


@External
public void setStaking(Address _staking) {
onlyOwner();
staking.set(_staking);
}

@External(readonly = true)
public Address getStaking() {
return staking.get();
}


@External
public void setBalancedRewards(Address _balancedRewards) {
onlyOwner();
balancedRewards.set(_balancedRewards);
}

@External(readonly = true)
public Address getBalancedRewards() {
return balancedRewards.get();
}


@External
public void setSICX(Address _sICX) {
onlyOwner();
sICX.set(_sICX);
}

@External(readonly = true)
public Address getSICX() {
return sICX.get();
}

@External(readonly = true)
public LiquidityDistribution[] getDistributions() {
int size = distribution.size();
Expand Down Expand Up @@ -103,6 +139,7 @@ public void distribute() {
}



@External
public void tokenFallback(Address _from, BigInteger _value, byte[] _data) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ public void distribute() {
verify(sICX.mock).transfer(rewards, total, expectedData.toString().getBytes());
}

@Test
public void testPermissions() {
_testPermission("setStaking", Checks.Errors.ONLY_OWNER, staking.getAddress());
_testPermission("setBalancedRewards", Checks.Errors.ONLY_OWNER, rewards);
_testPermission("setSICX", Checks.Errors.ONLY_OWNER, sICX.getAddress());
_testPermission("configureDistributions", Checks.Errors.ONLY_OWNER, (Object)new LiquidityDistribution[0]);

}

private void _testPermission(String method, String error, Object... params) {
Account dummy = sm.createAccount();
Executable call = () -> pol.invoke(dummy, method, params);
expectErrorMessage(call, error);
}

public LiquidityDistribution newDist(String source, BigInteger share) {
LiquidityDistribution bucket = new LiquidityDistribution();
bucket.source = source;
Expand Down

0 comments on commit 683868e

Please sign in to comment.