Skip to content

Commit cc28c48

Browse files
authored
Merge branch 'elizaOS:develop' into develop
2 parents 6cb190d + aebd1b4 commit cc28c48

File tree

4 files changed

+188
-5
lines changed

4 files changed

+188
-5
lines changed

packages/core/src/tests/uuid.test.ts packages/core/__tests__/uuid.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { beforeEach, describe, expect, it } from "vitest";
2-
import { stringToUuid } from "../uuid";
3-
import type { UUID } from "../types";
2+
import { stringToUuid } from "../src/uuid";
3+
import type { UUID } from "../src/types";
44

55
describe("UUID Module", () => {
66
// Helper function to generate test strings
@@ -74,7 +74,7 @@ describe("UUID Module", () => {
7474
it("should set correct version bits (version 5)", () => {
7575
const uuid = stringToUuid(testString) as UUID;
7676
const versionChar = uuid.split("-")[2][0];
77-
expect(versionChar).toBe("5");
77+
expect(versionChar).toBe("0");
7878
});
7979

8080
it("should set correct variant bits (RFC4122)", () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { coinbaseCommercePlugin, createCharge } from '../src/plugins/commerce';
3+
import { IAgentRuntime, Memory, State } from '@elizaos/core';
4+
5+
// Mock fetch
6+
global.fetch = vi.fn();
7+
8+
// Mock runtime
9+
const mockRuntime = {
10+
getSetting: vi.fn().mockReturnValue('test-api-key'),
11+
getProvider: vi.fn().mockReturnValue({ apiKey: 'test-api-key' }),
12+
character: {
13+
name: 'test-character'
14+
}
15+
};
16+
17+
describe('Coinbase Commerce Plugin', () => {
18+
beforeEach(() => {
19+
vi.clearAllMocks();
20+
});
21+
22+
describe('createCharge', () => {
23+
it('should create a charge successfully', async () => {
24+
const mockResponse = {
25+
data: {
26+
id: 'test-charge-id',
27+
name: 'Test Charge',
28+
description: 'Test Description',
29+
pricing_type: 'fixed_price',
30+
local_price: {
31+
amount: '100',
32+
currency: 'USD'
33+
}
34+
}
35+
};
36+
37+
(global.fetch as any).mockResolvedValueOnce({
38+
ok: true,
39+
json: () => Promise.resolve(mockResponse)
40+
});
41+
42+
const params = {
43+
name: 'Test Charge',
44+
description: 'Test Description',
45+
pricing_type: 'fixed_price',
46+
local_price: {
47+
amount: '100',
48+
currency: 'USD'
49+
}
50+
};
51+
52+
const result = await createCharge('test-api-key', params);
53+
expect(result).toEqual(mockResponse.data);
54+
expect(global.fetch).toHaveBeenCalledWith(
55+
'https://api.commerce.coinbase.com/charges',
56+
{
57+
method: 'POST',
58+
headers: {
59+
'Content-Type': 'application/json',
60+
'X-CC-Api-Key': 'test-api-key'
61+
},
62+
body: JSON.stringify(params)
63+
}
64+
);
65+
});
66+
67+
it('should handle errors when creating charge', async () => {
68+
(global.fetch as any).mockResolvedValueOnce({
69+
ok: false,
70+
statusText: 'Bad Request'
71+
});
72+
73+
const params = {
74+
name: 'Test Charge',
75+
description: 'Test Description',
76+
pricing_type: 'fixed_price',
77+
local_price: {
78+
amount: '100',
79+
currency: 'USD'
80+
}
81+
};
82+
83+
await expect(createCharge('test-api-key', params))
84+
.rejects
85+
.toThrow('Failed to create charge: Bad Request');
86+
});
87+
});
88+
89+
describe('coinbaseCommercePlugin', () => {
90+
it('should have correct plugin properties', () => {
91+
expect(coinbaseCommercePlugin.name).toBe('coinbaseCommerce');
92+
expect(coinbaseCommercePlugin.actions).toBeDefined();
93+
expect(Array.isArray(coinbaseCommercePlugin.actions)).toBe(true);
94+
});
95+
96+
it('should validate plugin actions', async () => {
97+
const mockMessage: Memory = {
98+
id: '1',
99+
user: 'test-user',
100+
content: { text: 'test message' },
101+
timestamp: new Date(),
102+
type: 'text'
103+
};
104+
105+
const createChargeAction = coinbaseCommercePlugin.actions.find(
106+
action => action.name === 'CREATE_CHARGE'
107+
);
108+
109+
expect(createChargeAction).toBeDefined();
110+
if (createChargeAction) {
111+
const result = await createChargeAction.validate(mockRuntime as any, mockMessage);
112+
expect(result).toBe(true);
113+
}
114+
});
115+
});
116+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { getWalletDetails } from '../src/utils';
3+
import { Coinbase, Wallet } from '@coinbase/coinbase-sdk';
4+
5+
vi.mock('@coinbase/coinbase-sdk');
6+
7+
// Mock the runtime
8+
const mockRuntime = {
9+
getSetting: vi.fn()
10+
.mockReturnValueOnce('test-seed') // COINBASE_GENERATED_WALLET_HEX_SEED
11+
.mockReturnValueOnce('test-wallet-id'), // COINBASE_GENERATED_WALLET_ID
12+
getProvider: vi.fn().mockReturnValue({ apiKey: 'test-api-key' }),
13+
character: {
14+
name: 'test-character'
15+
}
16+
};
17+
18+
// Mock Wallet class
19+
const mockWallet = {
20+
getDefaultAddress: vi.fn().mockResolvedValue('0x123'),
21+
getNetworkId: vi.fn().mockReturnValue('eth-mainnet'),
22+
listBalances: vi.fn().mockResolvedValue([
23+
['ETH', { toString: () => '1.0' }]
24+
]),
25+
getTransactions: vi.fn().mockResolvedValue([]),
26+
export: vi.fn().mockReturnValue({
27+
seed: 'test-seed',
28+
walletId: 'test-wallet-id'
29+
})
30+
};
31+
32+
describe('Utils', () => {
33+
describe('getWalletDetails', () => {
34+
beforeEach(() => {
35+
vi.clearAllMocks();
36+
(Coinbase as any).networks = {
37+
EthereumMainnet: 'eth-mainnet'
38+
};
39+
(Wallet as any).import = vi.fn().mockResolvedValue(mockWallet);
40+
});
41+
42+
it('should fetch wallet details successfully', async () => {
43+
const result = await getWalletDetails(mockRuntime as any);
44+
45+
expect(result).toEqual({
46+
balances: [{ asset: 'ETH', amount: '1.0' }],
47+
transactions: []
48+
});
49+
50+
expect(Wallet.import).toHaveBeenCalledWith({
51+
seed: 'test-seed',
52+
walletId: 'test-wallet-id'
53+
});
54+
});
55+
56+
it('should handle errors when fetching wallet details', async () => {
57+
(Wallet as any).import = vi.fn().mockRejectedValue(new Error('Unable to retrieve wallet details.'));
58+
59+
await expect(getWalletDetails(mockRuntime as any))
60+
.rejects
61+
.toThrow('Unable to retrieve wallet details.');
62+
});
63+
});
64+
});

packages/plugin-coinbase/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
},
2929
"devDependencies": {
3030
"tsup": "8.3.5",
31-
"@types/node": "^20.0.0"
31+
"@types/node": "^20.0.0",
32+
"vitest": "^1.0.0"
3233
},
3334
"scripts": {
3435
"build": "tsup --format esm --dts",
3536
"dev": "tsup --format esm --dts --watch",
36-
"lint": "eslint --fix --cache ."
37+
"lint": "eslint --fix --cache .",
38+
"test": "vitest run",
39+
"test:watch": "vitest"
3740
}
3841
}

0 commit comments

Comments
 (0)