Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
test(all): add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Oct 26, 2023
1 parent 93b9ecf commit 73287a5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
12 changes: 12 additions & 0 deletions bindings/encoding/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ func TestEncodeProverAssignment(t *testing.T) {
require.NotNil(t, encoded)
}

func TestEncodeProverAssignmentPayload(t *testing.T) {
encoded, err := EncodeProverAssignmentPayload(
common.BytesToHash(randomBytes(32)),
common.BytesToAddress(randomBytes(20)),
120,
[]TierFee{{Tier: 0, Fee: common.Big1}},
)

require.Nil(t, err)
require.NotNil(t, encoded)
}

func TestUnpackTxListBytes(t *testing.T) {
_, err := UnpackTxListBytes(randomBytes(1024))
require.NotNil(t, err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func CheckProverBalance(
rpc *Client,
prover common.Address,
taikoL1Address common.Address,
livenessBond *big.Int,
bond *big.Int,
) (bool, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
defer cancel()
Expand All @@ -57,7 +57,7 @@ func CheckProverBalance(

log.Info("Prover's deposited taikoTokenBalance", "balance", depositedBalance.String(), "address", prover.Hex())

if livenessBond.Cmp(depositedBalance) > 0 {
if bond.Cmp(depositedBalance) > 0 {
// Check allowance on taiko token contract
allowance, err := rpc.TaikoToken.Allowance(&bind.CallOpts{Context: ctxWithTimeout}, prover, taikoL1Address)
if err != nil {
Expand All @@ -74,14 +74,14 @@ func CheckProverBalance(

log.Info("Prover's wallet taiko token balance", "balance", balance.String(), "address", prover.Hex())

if livenessBond.Cmp(allowance) > 0 || livenessBond.Cmp(balance) > 0 {
if bond.Cmp(allowance) > 0 || bond.Cmp(balance) > 0 {
log.Info(
"Assigned prover does not have required on-chain token balance or allowance",
"providedProver", prover.Hex(),
"depositedBalance", depositedBalance.String(),
"taikoTokenBalance", balance,
"allowance", allowance.String(),
"proofBond", livenessBond,
"bond", bond,
)
return false, nil
}
Expand Down
17 changes: 17 additions & 0 deletions proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ func (s *ProposerTestSuite) TestProposeOp() {
s.Equal(types.ReceiptStatusSuccessful, receipt.Status)
}

func (s *ProposerTestSuite) TestProposeOpLocalsOnly() {
s.p.locals = []common.Address{common.BytesToAddress(testutils.RandomBytes(20))}
s.p.localsOnly = true

// Propose txs in L2 execution engine's mempool
sink := make(chan *bindings.TaikoL1ClientBlockProposed)

sub, err := s.p.rpc.TaikoL1.WatchBlockProposed(nil, sink, nil, nil)
s.Nil(err)
defer func() {
sub.Unsubscribe()
close(sink)
}()

s.Error(errNoNewTxs, s.p.ProposeOp(context.Background()))
}

func (s *ProposerTestSuite) TestProposeEmptyBlockOp() {
s.Nil(s.p.ProposeEmptyBlockOp(context.Background()))
}
Expand Down
3 changes: 1 addition & 2 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,7 @@ func (p *Prover) takeOneCapacity(blockID *big.Int) error {
// releaseOneCapacity releases one capacity to the capacity manager.
func (p *Prover) releaseOneCapacity(blockID *big.Int) {
if !p.IsGuardianProver() {
_, released := p.capacityManager.ReleaseOneCapacity(blockID.Uint64())
if !released {
if _, released := p.capacityManager.ReleaseOneCapacity(blockID.Uint64()); !released {
log.Error("Failed to release capacity", "id", blockID)
}
}
Expand Down

0 comments on commit 73287a5

Please sign in to comment.