Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qa test #118

Merged
merged 8 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions contracts/LiquidityBridgeContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable {

uint256 private minCollateral;
uint256 private minPegIn;
uint256 public maxQuoteValue;

uint32 private rewardP;
uint32 private resignDelayInBlocks;
uint private dust;
uint256 private maxQuoteValue;
uint providerId;

bool private locked;
Expand Down Expand Up @@ -237,6 +237,10 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable {
require(msg.sender == address(bridge), "Not allowed");
}

function getMaxQuoteValue() external view returns (uint256) {
return maxQuoteValue;
}

function getProviderIds() external view returns (uint) {
return providerId;
}
Expand Down Expand Up @@ -385,8 +389,6 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable {
"Max transaction value must be greater than min transaction value"
);
require(_maxTransactionValue <= maxQuoteValue, "Max transaction value can't be higher than maximum quote value");
uint256 bridgeMinimun = uint256(bridge.getMinimumLockTxValue());
require(_minTransactionValue >= bridgeMinimun, "Min transaction value can't be lower than bridge minimum lock tx value");
require(
bytes(_apiBaseUrl).length > 0,
"API base URL must not be empty"
Expand Down Expand Up @@ -763,12 +765,15 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable {
}

function depositPegout(
bytes32 quoteHash,
address lpAddress
PegOutQuote calldata quote
) external payable {
require(isRegisteredForPegout(lpAddress), "Provider not registered");
require(isRegisteredForPegout(quote.lpRskAddress), "Provider not registered");
bytes32 quoteHash = hashPegoutQuote(quote);
PegOutQuoteState storage state = pegOutQuotesStates[quoteHash];
require(!state.refunded, "LBC: Quote already refunded");
if(state.receivedAmount == 0) {
registeredPegoutQuotes[quoteHash] = quote;
}
state.receivedAmount += msg.value;
emit PegOutDeposit(quoteHash, state.receivedAmount, block.timestamp);
}
Expand All @@ -793,7 +798,6 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable {
);

pegOutQuotesStates[quoteHash].statusCode = PROCESSED_QUOTE_CODE;
registeredPegoutQuotes[quoteHash] = quote;

emit PegOut(
msg.sender,
Expand Down
79 changes: 35 additions & 44 deletions test/basic.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,6 @@ contract("LiquidityBridgeContract", async (accounts) => {
it("should validate provider limits on register", async () => {
const minCollateral = await instance.getMinCollateral();

await truffleAssertions.reverts(
instance.register(
"First contract",
10,
7200,
3600,
1,
100,
"http://localhost/api",
true,
"both",
{ from: accounts[1], value: minCollateral }
),
"Min transaction value can't be lower than bridge minimum lock tx value"
);

await truffleAssertions.reverts(
instance.register(
"First contract",
Expand Down Expand Up @@ -800,9 +784,6 @@ contract("LiquidityBridgeContract", async (accounts) => {
userPegInBalanceAfter.toString()
);
expect(+contractBalanceAfter).to.be.eq(+contractBalanceBefore - +msgValue);
// check that stores quote
const storedQuote = await instance.getRegisteredPegOutQuote(quoteHash)
expect(storedQuote.lbcAddress).to.not.be.eq('0x0000000000000000000000000000000000000000')
});

it("should fail on a false signature", async () => {
Expand Down Expand Up @@ -1213,30 +1194,40 @@ contract("LiquidityBridgeContract", async (accounts) => {
});

it("Should emit event when pegout is deposited", async () => {
const quoteHash =
"0x9fbfd385b8b19b130ae787ba3f14a0ab53274be939cdcf66018c9ba3014a8284";
const quote = utils.getTestPegOutQuote(
instance.address, //lbc address
liquidityProviderRskAddress,
accounts[2],
1
);
const quoteHash = await instance.hashPegoutQuote(quote);
const tx = await instance.depositPegout(
quoteHash,
liquidityProviderRskAddress,
quote,
{ value: web3.utils.toBN("500") }
);
await truffleAssertions.eventEmitted(tx, "PegOutDeposit", {
quoteHash: quoteHash,
accumulatedAmount: web3.utils.toBN("500"),
});
// check that stores quote
const storedQuote = await instance.getRegisteredPegOutQuote(quoteHash)
expect(storedQuote.lbcAddress).to.not.be.eq('0x0000000000000000000000000000000000000000')
});

it("Should update quote received amount when pegout is deposited", async () => {
const quoteHash =
"0x9fbfd385b8b19b130ae787ba3f14a0ab53274be939cdcf66118c9ba3014a8284";
const firstTx = await instance.depositPegout(
quoteHash,
const quote = utils.getTestPegOutQuote(
instance.address, //lbc address
liquidityProviderRskAddress,
accounts[2],
2
);
const quoteHash = await instance.hashPegoutQuote(quote);
const firstTx = await instance.depositPegout(
quote,
{ value: web3.utils.toBN("500") }
);
const secondTx = await instance.depositPegout(
quoteHash,
liquidityProviderRskAddress,
quote,
{ value: web3.utils.toBN("500") }
);
await truffleAssertions.eventEmitted(firstTx, "PegOutDeposit", {
Expand All @@ -1250,11 +1241,15 @@ contract("LiquidityBridgeContract", async (accounts) => {
});

it("Should fail if provider is not registered", async () => {
const quoteHash =
"0x9fbfd385b8b19b130ae787ba3f14a0ab53274be939cdcf66118c9ba3014a8284";
const tx = instance.depositPegout(quoteHash, accounts[4], {
value: web3.utils.toBN("500"),
});
const quote = utils.getTestPegOutQuote(
instance.address, //lbc address
liquidityProviderRskAddress,
accounts[2],
web3.utils.toBN(3)
);
await instance.resign();
await instance.withdrawPegoutCollateral();
const tx = instance.depositPegout(quote, { value: web3.utils.toBN("500") });
await truffleAssertions.reverts(tx, "Provider not registered");
});

Expand All @@ -1263,36 +1258,32 @@ contract("LiquidityBridgeContract", async (accounts) => {
instance.address, //lbc address
liquidityProviderRskAddress,
accounts[1],
web3.utils.toBN(1)
web3.utils.toBN(4)
);

// so its expired after deposit
quote.expireDate = quote.agreementTimestamp + 5
quote.expireBlock = await web3.eth.getBlock("latest").then(block => block.number + 1);

const quoteHash = await instance.hashPegoutQuote(utils.asArray(quote));
const quoteHash = await instance.hashPegoutQuote(quote);

const signature = await web3.eth.sign(
quoteHash,
liquidityProviderRskAddress
);

const firstTx = await instance.depositPegout(
quoteHash,
liquidityProviderRskAddress,
{ value: web3.utils.toBN(1) }
);
const firstTx = await instance.depositPegout(quote, { value: web3.utils.toBN(4) });

await truffleAssertions.eventEmitted(firstTx, "PegOutDeposit", {
quoteHash: quoteHash,
accumulatedAmount: web3.utils.toBN(1),
accumulatedAmount: web3.utils.toBN(4),
});

const tx = await instance.refundUserPegOut(utils.asArray(quote), signature);
const tx = await instance.refundUserPegOut(quote, signature);

await truffleAssertions.eventEmitted(tx, "PegOutUserRefunded", {
quoteHash: quoteHash,
value: web3.utils.toBN(1),
value: web3.utils.toBN(4),
userAddress: quote.rskRefundAddress,
});
});
Expand Down
5 changes: 3 additions & 2 deletions test/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ async function ensureLiquidityProviderAvailable(
liquidityProviderRskAddress,
amount
) {
let lpIsAvailable = await instance.isOperational(liquidityProviderRskAddress);
if (!lpIsAvailable) {
let lpIsAvailableForPegin = await instance.isOperational(liquidityProviderRskAddress);
let lpIsAvailableForPegout = await instance.isOperationalForPegout(liquidityProviderRskAddress);
if (!lpIsAvailableForPegin || !lpIsAvailableForPegout) {
return await instance.register(
"First contract",
10,
Expand Down
2 changes: 1 addition & 1 deletion truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = {
settings: { // See the solidity docs for advice about optimization and evmVersion
optimizer: {
enabled: true,
runs: 50
runs: 1
},
evmVersion: "byzantium"
}
Expand Down