Skip to content

Commit

Permalink
fix: require creating a payment channel before depositing
Browse files Browse the repository at this point in the history
  • Loading branch information
bojidar-bg committed Dec 26, 2023
1 parent 145d6da commit 0ae5768
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contracts/src/Payment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ contract Payment {
address publisher = msg.sender;
Channel storage channel = channels[publisher][provider][podId];

if (channel.investedByPublisher == 0) revert DoesNotExist();

channel.investedByPublisher = channel.investedByPublisher + amount;
channel.unlockedAt = 0;

Expand Down
3 changes: 3 additions & 0 deletions contracts/test/Payment.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ contract PaymentTest is Test {
token.mint(1000);

token.approve(address(payment), 500);
vm.expectRevert(Payment.DoesNotExist.selector);
payment.deposit(provider, podId, 500);

payment.createChannel(provider, podId, 1, 500);

token.approve(address(payment), 500);
Expand Down

0 comments on commit 0ae5768

Please sign in to comment.