|
1 | 1 | package mock |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "sync" |
| 5 | + |
| 6 | + "github.com/ethereum/go-ethereum/common" |
4 | 7 | "github.com/ethereum/go-ethereum/core/types" |
5 | 8 | ) |
6 | 9 |
|
7 | 10 | type MockNFTDetector struct { |
8 | 11 | IsNFTTransactionFunc func(tx *types.Transaction) bool |
| 12 | + knownContracts sync.Map |
| 13 | + callCount int |
9 | 14 | } |
10 | 15 |
|
11 | 16 | func NewMockNFTDetector() *MockNFTDetector { |
12 | | - return &MockNFTDetector{ |
| 17 | + detector := &MockNFTDetector{ |
13 | 18 | IsNFTTransactionFunc: func(tx *types.Transaction) bool { |
14 | 19 | return false |
15 | 20 | }, |
16 | 21 | } |
| 22 | + |
| 23 | + // Initialize with some test NFT contract addresses |
| 24 | + testContracts := map[string]bool{ |
| 25 | + "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D": true, // Test BAYC |
| 26 | + "0x23581767a106ae21c074b2276D25e5C3e136a68b": true, // Test Moonbirds |
| 27 | + } |
| 28 | + |
| 29 | + for addr := range testContracts { |
| 30 | + detector.knownContracts.Store(common.HexToAddress(addr), true) |
| 31 | + } |
| 32 | + |
| 33 | + return detector |
17 | 34 | } |
18 | 35 |
|
19 | 36 | func (m *MockNFTDetector) IsNFTTransaction(tx *types.Transaction) bool { |
| 37 | + m.callCount++ |
| 38 | + |
20 | 39 | if m.IsNFTTransactionFunc != nil { |
21 | 40 | return m.IsNFTTransactionFunc(tx) |
22 | 41 | } |
23 | | - return false |
| 42 | + |
| 43 | + // Default implementation using known contracts |
| 44 | + if tx.To() == nil { |
| 45 | + return false |
| 46 | + } |
| 47 | + |
| 48 | + isContract, exists := m.knownContracts.Load(*tx.To()) |
| 49 | + return exists && isContract.(bool) |
| 50 | +} |
| 51 | + |
| 52 | +// Helper methods for testing |
| 53 | +func (m *MockNFTDetector) GetCallCount() int { |
| 54 | + return m.callCount |
| 55 | +} |
| 56 | + |
| 57 | +func (m *MockNFTDetector) AddKnownContract(address common.Address) { |
| 58 | + m.knownContracts.Store(address, true) |
| 59 | +} |
| 60 | + |
| 61 | +func (m *MockNFTDetector) RemoveKnownContract(address common.Address) { |
| 62 | + m.knownContracts.Delete(address) |
| 63 | +} |
| 64 | + |
| 65 | +func (m *MockNFTDetector) Reset() { |
| 66 | + m.callCount = 0 |
| 67 | + m.knownContracts = sync.Map{} |
24 | 68 | } |
0 commit comments