Skip to content

Commit

Permalink
Merge pull request #176 from rsksmart/QA-Test
Browse files Browse the repository at this point in the history
Qa test
  • Loading branch information
MaximStanciu8 authored Oct 9, 2023
2 parents f11d981 + 9771146 commit 47e94fb
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ coverage.json
.secret
.DS_Store
integration-test/test.config.json
.env
52 changes: 24 additions & 28 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"deployed": false
},
"SignatureValidator": {
"address": "0xFe2746b892fFFf26E9a8F45935E7510d72028416",
"address": "0x9ffA71ad9ED6F23900EE8b753F7910Fb80D22CD5",
"deployed": true
},
"LiquidityBridgeContractAdmin": {
"address": "0x1de4FF655DC7BC289cCa9D232755005265B4C94b",
"deployed": false
},
"LiquidityBridgeContract": {
"address": "0x890D3AFD0F14D870DE24798329bf36ce8939D0b4",
"address": "0xc2E56a5518B17C5d88eBd67C6ED6e12AB5Ec7fef",
"deployed": true
},
"LiquidityBridgeContractProxy": {
Expand All @@ -23,70 +23,66 @@
"Migrations": {
"address": "0x9574a4972320d9988C110dAF950c89CC638B3b75",
"deployed": true
},
"Quotes": {
"address": "0x826186c06DA7b106A7aCBcB1E8E6AcbE5fA3Ab5F",
"deployed": true
},
"BtcUtils": {
"address": "0x1c30E87C717e80A19AD5BEa9AF57b20d98bCcb5B",
"deployed": true
}
},
"rskRegtest": {
"Migrations": {
"address": "0xdac5481925A298B95Bf5b54c35b68FC6fc2eF423",
"address": "0x1Af2844A588759D0DE58abD568ADD96BB8B3B6D8",
"deployed": true
},
"SafeMath": {
"address": "",
"deployed": false
},
"SignatureValidator": {
"address": "0xeFb80DB9E2d943A492Bd988f4c619495cA815643",
"deployed": true
},
"LiquidityBridgeContractAdmin": {
"address": "0x73ec81da0C72DD112e06c09A6ec03B5544d26F05",
"deployed": true
},
"LiquidityBridgeContract": {
"address": "0xA66939ac57893C2E65425a5D66099Bc20C76D4CD",
"deployed": true
},
"LiquidityBridgeContractProxy": {
"address": "0x1eD614cd3443EFd9c70F04b6d777aed947A4b0c4",
"address": "0xCd5805d60Bbf9Afe69a394c2BDa10F6Dae2c39AF",
"deployed": true
},
"Quotes": {
"address": "0x463F29B11503e198f6EbeC9903b4e5AaEddf6D29",
"address": "0xdac5481925A298B95Bf5b54c35b68FC6fc2eF423",
"deployed": true
},
"BtcUtils": {
"address": "0xfD1dda8C3BC734Bc1C8e71F69F25BFBEe9cE9535",
"deployed": true
},
"LiquidityBridgeContract": {
"address": "0x987c1f13d417F7E04d852B44badc883E4E9782e1",
"deployed": true
}
},
"alphanet": {
"Migrations": {
"address": "0x97CF123cFaB0720D4Bff758f3EF441F8867C38B0",
"address": "0x54D5d3e94Fe0542f9de230cf47e544Bbb7C9C1dd",
"deployed": true
},
"SignatureValidator": {
"address": "0x536Fc3732Edcc90e0970CF3Ba0D8FF25bc91EEeb",
"address": "0x7eAdDF7Aa126027Bd31F4aCADf4D1d0830a14763",
"deployed": true
},
"Quotes": {
"address": "0xaCF13405051Ab20e13d5F30Fadec46837CFb0065",
"address": "0x1A0898B4Ac6ed5BF1576237A1709cF791083d915",
"deployed": true
},
"BtcUtils": {
"address": "0xa841Cf63635A86ba39E8Cbaf8795f757d3Ec83B4",
"address": "0x6D69F04179e093C53Bf2DEc8147E15406c0aFdB4",
"deployed": true
},
"LiquidityBridgeContractAdmin": {
"address": "0x5fb9966EF4D07C81E3165FD60adC8563A76B93bD",
"deployed": true
"deployed": false
},
"LiquidityBridgeContract": {
"address": "0x4b8763082e70ba997c685C77D8172142D1db40cb",
"address": "0xDFED830702fd9339Ae826Ae0F1DF834163e4bBa6",
"deployed": true
},
"LiquidityBridgeContractProxy": {
"address": "0x0848B16e015A5e8A5c40Bfa0387367Be2fD371cf",
"deployed": true
"deployed": false
}
}
}
36 changes: 24 additions & 12 deletions contracts/LiquidityBridgeContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable, Reentranc
bool success,
bytes32 quoteHash
);
event PegInRegistered(bytes32 indexed quoteHash, int256 transferredAmount);
event Penalized(address liquidityProvider, uint penalty, bytes32 quoteHash);
event BridgeCapExceeded(bytes32 quoteHash, int256 errorCode);
event BalanceIncrease(address dest, uint amount);
Expand All @@ -82,15 +83,15 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable, Reentranc
bytes32 quotehash,
uint processed
);
event PegOutRefunded(bytes32 quoteHash);
event PegOutRefunded(bytes32 indexed quoteHash);
event PegOutDeposit(
bytes32 quoteHash,
bytes32 indexed quoteHash,
address indexed sender,
uint256 indexed amount,
uint256 indexed timestamp
uint256 amount,
uint256 timestamp
);
event PegOutUserRefunded(
bytes32 quoteHash,
bytes32 indexed quoteHash,
uint256 value,
address userAddress
);
Expand Down Expand Up @@ -156,6 +157,8 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable, Reentranc
bool _mainnet
) external initializer {
require(_rewardPercentage <= 100, "LBC004");
require(_minimumCollateral >= 0.6 ether, "LBC072");
require(_resignDelayBlocks >= 15, "LBC073");
__Ownable_init_unchained();
bridge = Bridge(_bridgeAddress);
minCollateral = _minimumCollateral;
Expand Down Expand Up @@ -263,17 +266,25 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable, Reentranc
_apiBaseUrl,
_providerType
);
// TODO multiplication by 2 is a temporal fix until we define solution with product team

require(collateral[msg.sender] == 0 && pegoutCollateral[msg.sender] == 0, "LBC070");
require(msg.value >= minCollateral * 2, "LBC008");
require(
resignationBlockNum[msg.sender] == 0,
"LBC009"
);
// TODO split 50/50 between pegin and pegout is a temporal fix until we define solution with product team
uint halfMsgValue = msg.value / 2;
collateral[msg.sender] = msg.value % 2 == 0 ? halfMsgValue : halfMsgValue + 1;
pegoutCollateral[msg.sender] = halfMsgValue;

if (keccak256(abi.encodePacked(_providerType)) == keccak256(abi.encodePacked("pegin"))) {
require(msg.value >= minCollateral, "LBC008");
collateral[msg.sender] = msg.value;
} else if (keccak256(abi.encodePacked(_providerType)) == keccak256(abi.encodePacked("pegout"))) {
require(msg.value >= minCollateral, "LBC008");
pegoutCollateral[msg.sender] = msg.value;
} else {
require(msg.value >= minCollateral * 2, "LBC008");
uint halfMsgValue = msg.value / 2;
collateral[msg.sender] = msg.value % 2 == 0 ? halfMsgValue : halfMsgValue + 1;
pegoutCollateral[msg.sender] = halfMsgValue;
}

providerId++;
liquidityProviders[providerId] = LiquidityProvider({
Expand Down Expand Up @@ -674,6 +685,7 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable, Reentranc
}
processedQuotes[quoteHash] = PROCESSED_QUOTE_CODE;
delete callRegistry[quoteHash];
emit PegInRegistered(quoteHash, transferredAmountOrErrorCode);
return transferredAmountOrErrorCode;
}

Expand All @@ -698,7 +710,7 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable, Reentranc
require(registeredQuote.lbcAddress == address(0), "LBC028");
registeredPegoutQuotes[quoteHash] = quote;
pegoutRegistry[quoteHash].depositTimestamp = block.timestamp;
emit PegOutDeposit(quoteHash, msg.sender , msg.value, block.timestamp);
emit PegOutDeposit(quoteHash, msg.sender, msg.value, block.timestamp);
}

function refundUserPegOut(
Expand Down
4 changes: 3 additions & 1 deletion errorCodes.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@
"LBC068": "Invalid destination for bitcoin transaction",
"LBC069": "Quote is not related to transaction",
"LBC070": "Liquidity provider already registered",
"LBC071": "Intentional overflow on quote values"
"LBC071": "Intentional overflow on quote values",
"LBC072": "Minimum collateral for registration can't be lower than 0.6 RBTC",
"LBC073": "Resign delay blocks lower than minimal"
}
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALPHANET_RPC_URL=http://127.0.0.1:4444
2 changes: 1 addition & 1 deletion integration-test/pegin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Flyover pegin process should', () => {
additionalGasLimit: quote.gasLimit + cfuExtraGas
})
const parsedReceipt = decodeLogs({ abi: LiquidityBridgeContract.abi, receipt })
expect(parsedReceipt.CallForUser.success).to.be.true
expect(parsedReceipt.CallForUser?.success).to.be.true
})

it('execute registerPegIn', async () => {
Expand Down
4 changes: 2 additions & 2 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const RSK_NETWORKS = [

const RSK_BRIDGE_ADDRESS = "0x0000000000000000000000000000000001000006";

const MINIMUM_COLLATERAL = "1"; // amount in wei
const MINIMUM_COLLATERAL = "600000000000000000"; // amount in wei
const MINIMUM_PEG_IN_DEFAULT = "5000000000000000"; // amount in wei
const MINIMUM_PEG_IN_REGTEST = "5000000000000000"; // amount in wei
const REWARD_PERCENTAGE = 10;
const RESIGN_DELAY_BLOCKS = 1;
const RESIGN_DELAY_BLOCKS = 15;
const DUST_THRESHOLD = 2300 * 65164000;
const MAX_QUOTE_VALUE = web3.utils.toBN("1000000000000000000"); // amount in wei
const BTC_BLOCK_TIME = 5400; // the 5400 addition is to give 1.5h to the tx to be mined
Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@openzeppelin/truffle-upgrades": "^1.17.1",
"@rsksmart/pmt-builder": "^3.0.0",
"bs58check": "^3.0.1",
"dotenv": "^16.3.1",
"prettier": "^2.4.1",
"prettier-plugin-solidity": "^1.0.0-beta.18",
"solc": "^0.8.3",
Expand Down
3 changes: 3 additions & 0 deletions readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,6 @@ Used by the user to deposit the payment of a pegout service

After the first dploy we don't have to change anymore the LiquidityBridgeContract.sol instead we need to create a new version like LiquidityBridgeContractV2.sol and uncomment and update the 3_upgrade_contracts.js script with the last version that will upgrade the contract.
With that we can easily get back on any mistake and swicth version.

#### Alphanet support
If you're working in your own alphanet you must have an environment variable called `ALPHANET_RPC_URL` with the RPC server url so truffle can run all the necessary scripts.
2 changes: 1 addition & 1 deletion scripts/registerProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (callback) {
)
.call({
// from: accounts[0],
value: 100000000000000000,
value: 1200000000000000000,
})
.then((response) => console.log("Success: " + response))
.catch((err) => console.log("Error: " + err));
Expand Down
5 changes: 5 additions & 0 deletions test/basic.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ contract("LiquidityBridgeContract", async (accounts) => {
"LBC021"
);
await instance.resign({ from: lpAddress });
await utils.mineBlocks(utils.RESIGN_DELAY_BLOCKS);
await instance.withdrawCollateral({ from: lpAddress });
});

Expand All @@ -392,6 +393,7 @@ contract("LiquidityBridgeContract", async (accounts) => {
);
await instance.resign({ from: lpAddress });
await truffleAssertions.reverts(instance.resign({ from: lpAddress }), "LBC001");
await utils.mineBlocks(utils.RESIGN_DELAY_BLOCKS);
await instance.withdrawCollateral({ from: lpAddress });
});

Expand Down Expand Up @@ -750,6 +752,8 @@ contract("LiquidityBridgeContract", async (accounts) => {
expect(initialLPBalance).to.be.a.bignumber.eq(lbcCurrBal);
expect(finalLPBalance).to.be.a.bignumber.eq(web3.utils.toBN(0));

await utils.mineBlocks(utils.RESIGN_DELAY_BLOCKS);

let withdrawCollateralTx = await instance.withdrawCollateral({ from: lpAddress });

let finalLPCol = await instance.getCollateral(lpAddress);
Expand Down Expand Up @@ -1241,6 +1245,7 @@ contract("LiquidityBridgeContract", async (accounts) => {
web3.utils.toBN(3)
);
await instance.resign({ from: lpAddress });
await utils.mineBlocks(utils.RESIGN_DELAY_BLOCKS);
await instance.withdrawPegoutCollateral({ from: lpAddress });
const quoteHash = await instance.hashPegoutQuote(quote);
const signature = await web3.eth.sign(quoteHash, lpAddress);
Expand Down
38 changes: 31 additions & 7 deletions test/miscellaneous.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,24 +369,48 @@ contract("LiquidityBridgeContract", async (accounts) => {
);
});

it("should validate minimiumCollateral arg in initialize", async () => {
let instance = await LiquidityBridgeContract.new();
const MAX_QUOTE_VALUE = web3.utils.toBN("1000000000000000000")
const MINIMUM_COLLATERAL = web3.utils.toBN("500000000000000000")
const RESIGN_DELAY_BLOCKS = 15
await truffleAssert.reverts(
instance.initialize(bridgeMockInstance.address, MINIMUM_COLLATERAL, 1, 50, RESIGN_DELAY_BLOCKS, 1, MAX_QUOTE_VALUE, 1, false),
"LBC072"
);
});

it("should validate resignDelayBlocks arg in initialize", async () => {
let instance = await LiquidityBridgeContract.new();
const MAX_QUOTE_VALUE = web3.utils.toBN("1000000000000000000")
const MINIMUM_COLLATERAL = web3.utils.toBN("600000000000000000")
const RESIGN_DELAY_BLOCKS = 14
await truffleAssert.reverts(
instance.initialize(bridgeMockInstance.address, MINIMUM_COLLATERAL, 1, 50, RESIGN_DELAY_BLOCKS, 1, MAX_QUOTE_VALUE, 1, false),
"LBC073"
);
});

it("should validate reward percentage arg in initialize", async () => {
let instance = await LiquidityBridgeContract.new();
const MAX_QUOTE_VALUE = web3.utils.toBN("1000000000000000000")
await instance.initialize(bridgeMockInstance.address, 1, 1, 0, 1, 1, MAX_QUOTE_VALUE, 1, false);
const MINIMUM_COLLATERAL = web3.utils.toBN("600000000000000000")
const RESIGN_DELAY_BLOCKS = 15
await instance.initialize(bridgeMockInstance.address, MINIMUM_COLLATERAL, 1, 0, RESIGN_DELAY_BLOCKS, 1, MAX_QUOTE_VALUE, 1, false);
instance = await LiquidityBridgeContract.new();
await instance.initialize(bridgeMockInstance.address, 1, 1, 0, 1, 1, MAX_QUOTE_VALUE, 1, false);
await instance.initialize(bridgeMockInstance.address, MINIMUM_COLLATERAL, 1, 0, RESIGN_DELAY_BLOCKS, 1, MAX_QUOTE_VALUE, 1, false);
instance = await LiquidityBridgeContract.new();
await instance.initialize(bridgeMockInstance.address, 1, 1, 1, 1, 1, MAX_QUOTE_VALUE, 1, false);
await instance.initialize(bridgeMockInstance.address, MINIMUM_COLLATERAL, 1, 1, RESIGN_DELAY_BLOCKS, 1, MAX_QUOTE_VALUE, 1, false);
instance = await LiquidityBridgeContract.new();
await instance.initialize(bridgeMockInstance.address, 1, 1, 99, 1, 1, MAX_QUOTE_VALUE, 1, false);
await instance.initialize(bridgeMockInstance.address, MINIMUM_COLLATERAL, 1, 99, RESIGN_DELAY_BLOCKS, 1, MAX_QUOTE_VALUE, 1, false);
instance = await LiquidityBridgeContract.new();
await instance.initialize(bridgeMockInstance.address, 1, 1, 100, 1, 1, MAX_QUOTE_VALUE, 1, false);
await instance.initialize(bridgeMockInstance.address, MINIMUM_COLLATERAL, 1, 100, RESIGN_DELAY_BLOCKS, 1, MAX_QUOTE_VALUE, 1, false);
await truffleAssert.fails(
instance.initialize(bridgeMockInstance.address, 1, 1, 100, 1, 1, MAX_QUOTE_VALUE, 1, false)
instance.initialize(bridgeMockInstance.address, MINIMUM_COLLATERAL, 1, 100, RESIGN_DELAY_BLOCKS, 1, MAX_QUOTE_VALUE, 1, false)
);
instance = await LiquidityBridgeContract.new();
await truffleAssert.fails(
instance.initialize(bridgeMockInstance.address, 1, 1, 101, 1, 1, MAX_QUOTE_VALUE, 1, false)
instance.initialize(bridgeMockInstance.address, MINIMUM_COLLATERAL, 1, 101, RESIGN_DELAY_BLOCKS, 1, MAX_QUOTE_VALUE, 1, false)
);
});

Expand Down
Loading

0 comments on commit 47e94fb

Please sign in to comment.