Skip to content

Commit

Permalink
Add DepositEvent and checks for it
Browse files Browse the repository at this point in the history
  • Loading branch information
vp4242 committed Feb 20, 2024
1 parent c9d0887 commit a3e2982
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions contracts/0.8.9/SepoliaDepositAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import "@openzeppelin/contracts-v4.4/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-v4.4/access/Ownable.sol";

interface IDepositContract {
event DepositEvent(
bytes pubkey,
bytes withdrawal_credentials,
bytes amount,
bytes signature,
bytes index
);

function deposit(
bytes calldata pubkey,
bytes calldata withdrawal_credentials,
Expand Down
18 changes: 14 additions & 4 deletions test/0.8.9/sepolia-deposit-adapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ const { ETH } = require('../helpers/utils')
const { EvmSnapshot } = require('../helpers/blockchain')

const SepoliaDepositAdapter = artifacts.require('SepoliaDepositAdapter')
const SepoliaDepositContract = artifacts.require('ISepoliaDepositContract')

// To run Sepolia Deposit Adapter tests:
// HARDHAT_FORKING_URL=<rpc url> HARDHAT_CHAIN_ID=11155111 npx hardhat test --grep "SepoliaDepositAdapter"
contract('SepoliaDepositAdapter', ([deployer]) => {
let depositAdapter
let snapshot
let bepoliaToken
const sepoliaDepositContract = '0x7f02C3E3c98b133055B8B348B2Ac625669Ed295D'
const sepoliaDepositContractAddress = '0x7f02C3E3c98b133055B8B348B2Ac625669Ed295D'
const EOAddress = '0x6885E36BFcb68CB383DfE90023a462C03BCB2AE5'
const bepoliaTokenHolder = EOAddress
// const log = console.log
Expand All @@ -24,10 +25,10 @@ contract('SepoliaDepositAdapter', ([deployer]) => {
return this.skip()
}

depositAdapter = await SepoliaDepositAdapter.new(sepoliaDepositContract)
depositAdapter = await SepoliaDepositAdapter.new(sepoliaDepositContractAddress)
log('depositAdapter address', depositAdapter.address)

bepoliaToken = await ethers.getContractAt('ISepoliaDepositContract', sepoliaDepositContract)
bepoliaToken = await ethers.getContractAt('ISepoliaDepositContract', sepoliaDepositContractAddress)

const code = await ethers.provider.getCode(depositAdapter.address)
assert.notEqual(code, '0x')
Expand Down Expand Up @@ -97,11 +98,20 @@ contract('SepoliaDepositAdapter', ([deployer]) => {
const depositCountBefore = await depositAdapter.get_deposit_count()
log('depositCount', depositCountBefore)

const sepoliaDepositContract = await SepoliaDepositContract.at(sepoliaDepositContractAddress)

const receipt = await depositAdapter.deposit(key, withdrawalCredentials, sig, dataRoot, {
from: owner.address,
value: ETH(32),
})
assert.emits(receipt, 'EthReceived', { sender: sepoliaDepositContract, amount: ETH(32) })
assert.emits(receipt, 'EthReceived', { sender: sepoliaDepositContractAddress, amount: ETH(32) })
const depositEvents = await sepoliaDepositContract.getPastEvents('DepositEvent')
assert.equals(depositEvents.length, 1)
log('depositEvents', depositEvents, ETH(32))

assert.equals(depositEvents[0].args.pubkey, key)
assert.equals(depositEvents[0].args.withdrawal_credentials, withdrawalCredentials)
assert.equals(depositEvents[0].args.signature, sig)

const depositRootAfter = await depositAdapter.get_deposit_root()
log('depositRoot After', depositRootAfter)
Expand Down

0 comments on commit a3e2982

Please sign in to comment.