-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2345 from ai16z-demirix/feature/solana-plugin-tests
feat: adding tests for plugin-solana
- Loading branch information
Showing
4 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
|
||
describe('Swap Action', () => { | ||
describe('validate', () => { | ||
it('should handle swap message validation', async () => { | ||
const mockMessage = { | ||
content: 'Swap 1 SOL to USDC', | ||
metadata: { | ||
fromToken: 'SOL', | ||
toToken: 'USDC', | ||
amount: '1' | ||
} | ||
}; | ||
|
||
// Basic test to ensure message structure | ||
expect(mockMessage.metadata).toBeDefined(); | ||
expect(mockMessage.metadata.fromToken).toBe('SOL'); | ||
expect(mockMessage.metadata.toToken).toBe('USDC'); | ||
expect(mockMessage.metadata.amount).toBe('1'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { trustEvaluator } from '../../src/evaluators/trust'; | ||
|
||
// Mock the core module | ||
vi.mock('@elizaos/core', () => ({ | ||
generateTrueOrFalse: vi.fn().mockResolvedValue(false), | ||
ModelClass: { | ||
SMALL: 'small' | ||
}, | ||
settings: { | ||
MAIN_WALLET_ADDRESS: 'test-wallet-address' | ||
}, | ||
booleanFooter: 'Answer with Yes or No.', | ||
elizaLogger: { | ||
log: vi.fn(), | ||
debug: vi.fn(), | ||
info: vi.fn(), | ||
error: vi.fn() | ||
}, | ||
composeContext: vi.fn().mockReturnValue({ | ||
state: {}, | ||
template: '' | ||
}) | ||
})); | ||
|
||
describe('Trust Evaluator', () => { | ||
it('should handle non-trust messages', async () => { | ||
const mockRuntime = { | ||
getSetting: vi.fn(), | ||
composeState: vi.fn().mockResolvedValue({ | ||
agentId: 'test-agent', | ||
roomId: 'test-room' | ||
}), | ||
getLogger: vi.fn().mockReturnValue({ | ||
debug: vi.fn(), | ||
info: vi.fn(), | ||
log: vi.fn(), | ||
error: vi.fn() | ||
}) | ||
}; | ||
|
||
const mockMessage = { | ||
content: 'Hello world', | ||
metadata: {} | ||
}; | ||
|
||
const mockState = { | ||
agentId: 'test-agent', | ||
roomId: 'test-room' | ||
}; | ||
|
||
const result = await trustEvaluator.handler(mockRuntime, mockMessage, mockState); | ||
expect(result).toBeDefined(); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/plugin-solana/__tests__/providers/token-security.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { TokenProvider } from '../../src/providers/token'; | ||
import { WalletProvider } from '../../src/providers/wallet'; | ||
import { ICacheManager } from '@elizaos/core'; | ||
|
||
describe('Token Security', () => { | ||
it('should handle empty security data gracefully', async () => { | ||
const mockCacheManager = { | ||
get: vi.fn().mockResolvedValue(null), | ||
set: vi.fn(), | ||
delete: vi.fn(), | ||
clear: vi.fn(), | ||
has: vi.fn(), | ||
}; | ||
|
||
const mockWalletProvider = new WalletProvider(mockCacheManager); | ||
const tokenProvider = new TokenProvider( | ||
'So11111111111111111111111111111111111111112', | ||
mockWalletProvider, | ||
mockCacheManager | ||
); | ||
|
||
global.fetch = vi.fn().mockResolvedValueOnce({ | ||
ok: true, | ||
json: () => Promise.resolve({ | ||
success: true, | ||
data: {} | ||
}) | ||
}); | ||
|
||
const result = await tokenProvider.fetchTokenSecurity(); | ||
expect(result).toBeDefined(); | ||
expect(result.ownerBalance).toBe(undefined); | ||
expect(result.creatorBalance).toBe(undefined); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
...ges/plugin-solana/src/tests/token.test.ts → ...ges/plugin-solana/__tests__/token.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters