ChainSafe / ChainSafe/canton-middleware

chore: consolidate Token mock into a single shared package

Open
#270 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1
Forks
1
Avg merge
40m
Merged PRs (30d)
1

Description

## Background

The `Token` interface mock (`mock_canton_token.go`, 924 lines of mockery-generated code) is currently duplicated across multiple consumer packages:

- `pkg/token/mocks/mock_canton_token.go`
- `pkg/transfer/mocks/mock_canton_token.go`

PR #268 (AcceptWorker) adds a third copy at `pkg/custodial/mocks/mock_canton_token.go`. Once that PR merges, we'll have ~3000 lines of identical generated code across three locations, and any future consumer of `Token` will likely add a fourth.

## Cost

- Every change to the `Token` interface (in `pkg/cantonsdk/token/client.go`) requires regenerating all copies — easy to forget one and end up with skewed mocks.
- ~3000 lines of identical generated code in the repo.
- Increases diff noise on PRs that touch the `Token` interface.

## Proposed solution

Move the mock to a single shared location alongside the interface definition:

- `pkg/cantonsdk/token/mocks/mock_canton_token.go`

All consumer packages (`pkg/token`, `pkg/transfer`, `pkg/custodial`, and any future consumers) import from there.

Mockery's `--srcpkg` flag already supports this pattern. PR #268's `pkg/custodial/accept_worker.go:21` `go:generate` directive uses it:

```go
//go:generate mockery --srcpkg github.com/chainsafe/canton-middleware/pkg/cantonsdk/token --name Token --output ./mocks --filename mock_canton_token.go
```

The same directive can live once in `pkg/cantonsdk/token/` and emit a single mock package.

## Sequencing

This should land **after PR #268 merges** so we consolidate from the full known set of consumers. Otherwise we'd just have to redo the consolidation when #268 lands.

## Out of scope

- Other interface mocks in the codebase — this issue is scoped to `Token` only. If similar duplication exists for other interfaces, those can be follow-ups.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.