Skip to content

Commit

Permalink
Add an event for deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Aug 5, 2023
1 parent dd4645a commit 5e9d55b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions contracts/ValidatorCollection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ contract ValidatorCollection {

/// @notice 검증자가 추가될 때 발생되는 이벤트
event Added(address validator, uint256 start, uint256 balance, Status status);
/// @notice 자금이 입급될 때 발생되는 이벤트
event Deposited(address validator, uint256 amount, uint256 balance);

/// @notice 생성자
/// @param _validators 초기에 설정될 검증자이다. 예치금이 예치된 후 그 즉시 활성화 된다.
Expand Down Expand Up @@ -67,5 +69,7 @@ contract ValidatorCollection {
validators[msg.sender].balance += _amount;

if (validators[msg.sender].balance >= MINIMUM_DEPOSIT_AMOUNT) validators[msg.sender].status = Status.ACTIVE;

emit Deposited(msg.sender, _amount, validators[msg.sender].balance);
}
}
8 changes: 6 additions & 2 deletions test/ValidatorCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ describe("Test for LinkCollection", () => {
it("Deposit 25,000", async () => {
for (const elem of validators) {
await tokenContract.connect(elem).approve(contract.address, halfAmount.value);
await contract.connect(elem).deposit(halfAmount.value);
await expect(contract.connect(elem).deposit(halfAmount.value))
.to.emit(contract, "Deposited")
.withArgs(elem.address, halfAmount.value, halfAmount.value);
let item = await contract.validators(elem.address);
assert.deepStrictEqual(item.validator, elem.address);
assert.deepStrictEqual(item.status, 2);
Expand All @@ -78,7 +80,9 @@ describe("Test for LinkCollection", () => {
it("Deposit 50,000", async () => {
for (const elem of validators) {
await tokenContract.connect(elem).approve(contract.address, halfAmount.value);
await contract.connect(elem).deposit(halfAmount.value);
await expect(contract.connect(elem).deposit(halfAmount.value))
.to.emit(contract, "Deposited")
.withArgs(elem.address, halfAmount.value, amount.value);
let item = await contract.validators(elem.address);
assert.deepStrictEqual(item.validator, elem.address);
assert.deepStrictEqual(item.status, 1);
Expand Down

0 comments on commit 5e9d55b

Please sign in to comment.