@pasosdejesus/m 0.22.0 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/debug/DebugConsole.js +6 -6
- package/dist/debug/DebugConsole.js.map +1 -1
- package/dist/debug/Logger.js +2 -2
- package/dist/debug/Logger.js.map +1 -1
- package/dist/e2e/assertions.js +3 -3
- package/dist/e2e/assertions.js.map +1 -1
- package/dist/e2e/env.js +3 -3
- package/dist/e2e/env.js.map +1 -1
- package/dist/i18n/common-cli.js +2 -2
- package/dist/i18n/common-cli.js.map +1 -1
- package/dist/tasks/context-reqs.d.ts.map +1 -1
- package/dist/tasks/context-reqs.js +1 -0
- package/dist/tasks/context-reqs.js.map +1 -1
- package/dist/tasks/db.js +5 -5
- package/dist/tasks/db.js.map +1 -1
- package/dist/tasks/edit.js +44 -44
- package/dist/tasks/edit.js.map +1 -1
- package/dist/tasks/engine.js +2 -2
- package/dist/tasks/engine.js.map +1 -1
- package/dist/tasks/env-diff.js +2 -2
- package/dist/tasks/env-diff.js.map +1 -1
- package/dist/tasks/glob.js +6 -6
- package/dist/tasks/glob.js.map +1 -1
- package/dist/tasks/grep.js +9 -9
- package/dist/tasks/grep.js.map +1 -1
- package/dist/tasks/readfile.js +17 -17
- package/dist/tasks/readfile.js.map +1 -1
- package/dist/tasks/req.js +17 -17
- package/dist/tasks/req.js.map +1 -1
- package/dist/tasks/wallet.js +15 -15
- package/dist/tasks/wallet.js.map +1 -1
- package/dist/tasks/writefile.js +8 -8
- package/dist/tasks/writefile.js.map +1 -1
- package/dist/templates/AGENTS.md.hbs +2 -2
- package/dist/templates/ARCHITECTURE.md.hbs +2 -2
- package/dist/templates/CONTRIBUTING.md.hbs +2 -2
- package/dist/templates/apps/.env.example.hbs +1 -1
- package/dist/templates/apps/hardhat/package.json +1 -1
- package/dist/templates/apps/hardhat/scripts/verifyDeployment.ts +10 -10
- package/dist/templates/apps/hardhat/sync-abis.mjs +3 -3
- package/dist/templates/apps/nextjs/app/page.tsx.hbs +2 -2
- package/package.json +3 -2
- package/src/blockchain/README.md +1 -1
- package/src/debug/README.md +1 -1
- package/src/e2e/README.md +2 -2
- package/src/tasks/README.md +9 -9
- package/src/test-utils/README.md +16 -16
- package/dist/templates/apps/hardhat/contracts/MockUSDT.sol +0 -47
- package/dist/templates/apps/hardhat/test/MockUSDT.test.ts +0 -40
|
@@ -8,25 +8,25 @@ async function main() {
|
|
|
8
8
|
"LearnTGVaults",
|
|
9
9
|
process.env.NEXT_PUBLIC_DEPLOYED_AT // The deployed address
|
|
10
10
|
);
|
|
11
|
-
console.log("
|
|
11
|
+
console.log("LearnTGVaults Verification");
|
|
12
12
|
console.log("=============================");
|
|
13
13
|
console.log("Contract address:", process.env.NEXT_PUBLIC_DEPLOYED_AT);
|
|
14
14
|
|
|
15
15
|
// Get the owner of the contract
|
|
16
16
|
const owner = await learnTGVaults.owner();
|
|
17
|
-
console.log("\
|
|
17
|
+
console.log("\nContract owner:", owner);
|
|
18
18
|
|
|
19
19
|
// Get the USDT token address that the contract was initialized with
|
|
20
20
|
const usdtToken = await learnTGVaults.usdtToken();
|
|
21
|
-
console.log("
|
|
21
|
+
console.log("Contract USDT token address:", usdtToken);
|
|
22
22
|
|
|
23
23
|
// Get the cCop token address that the contract was initialized with
|
|
24
24
|
const cCopToken = await learnTGVaults.cCopToken();
|
|
25
|
-
console.log("
|
|
25
|
+
console.log("Contract cCop token address:", cCopToken);
|
|
26
26
|
|
|
27
27
|
// Get the gooddollar token address that the contract was initialized with
|
|
28
28
|
const gooddollarToken = await learnTGVaults.gooddollarToken();
|
|
29
|
-
console.log("
|
|
29
|
+
console.log("Contract gooddollar token address:", gooddollarToken);
|
|
30
30
|
|
|
31
31
|
// Get provider
|
|
32
32
|
const provider = ethers.provider;
|
|
@@ -35,7 +35,7 @@ async function main() {
|
|
|
35
35
|
const usdtContract = await ethers.getContractAt("IERC20", usdtToken);
|
|
36
36
|
const usdtDecimals = process.env.NEXT_PUBLIC_USDT_DECIMALS ? parseInt(process.env.NEXT_PUBLIC_USDT_DECIMALS) : 6;
|
|
37
37
|
|
|
38
|
-
console.log("\
|
|
38
|
+
console.log("\nBalance Verification");
|
|
39
39
|
console.log("=====================");
|
|
40
40
|
|
|
41
41
|
// 1. Check contract USDT balance
|
|
@@ -64,7 +64,7 @@ async function main() {
|
|
|
64
64
|
const deployerAddress = deployerWallet.address;
|
|
65
65
|
const deployerUSDTBalance = await usdtContract.balanceOf(deployerAddress);
|
|
66
66
|
const deployerCELOBalance = await provider.getBalance(deployerAddress);
|
|
67
|
-
console.log(`\
|
|
67
|
+
console.log(`\nDeployer account (from PRIVATE_KEY):`);
|
|
68
68
|
console.log(` Address: ${deployerAddress}`);
|
|
69
69
|
console.log(` USDT: ${ethers.formatUnits(deployerUSDTBalance, usdtDecimals)} USDT`);
|
|
70
70
|
console.log(` CELO: ${ethers.formatEther(deployerCELOBalance)} CELO`);
|
|
@@ -74,13 +74,13 @@ async function main() {
|
|
|
74
74
|
const hardhatAccount0 = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
|
|
75
75
|
const hardhatUSDTBalance = await usdtContract.balanceOf(hardhatAccount0);
|
|
76
76
|
const hardhatCELOBalance = await provider.getBalance(hardhatAccount0);
|
|
77
|
-
console.log(`\
|
|
77
|
+
console.log(`\nHardhat account #0 (common test):`);
|
|
78
78
|
console.log(` Address: ${hardhatAccount0}`);
|
|
79
79
|
console.log(` USDT: ${ethers.formatUnits(hardhatUSDTBalance, usdtDecimals)} USDT`);
|
|
80
80
|
console.log(` CELO: ${ethers.formatEther(hardhatCELOBalance)} CELO`);
|
|
81
81
|
|
|
82
|
-
console.log("\n
|
|
83
|
-
console.log("\
|
|
82
|
+
console.log("\n[OK] Contract deployed and verified successfully!");
|
|
83
|
+
console.log("\nSummary:");
|
|
84
84
|
console.log(" • LearnTGVaults contract is deployed and accessible");
|
|
85
85
|
console.log(" • Verify contract has sufficient USDT for rewards");
|
|
86
86
|
console.log(" • Verify contract has CELO for gas (if needed)");
|
|
@@ -32,7 +32,7 @@ function walkDir(dir) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// Main script
|
|
35
|
-
console.log("
|
|
35
|
+
console.log("Syncing ABIs to the frontend app...")
|
|
36
36
|
|
|
37
37
|
try {
|
|
38
38
|
// Find all artifact JSON files from Hardhat compilation
|
|
@@ -50,9 +50,9 @@ try {
|
|
|
50
50
|
console.log(`Copied ABI for ${contractName}`)
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
-
console.log("
|
|
53
|
+
console.log("[OK] ABI sync complete!")
|
|
54
54
|
|
|
55
55
|
} catch (error) {
|
|
56
|
-
console.error("
|
|
56
|
+
console.error("[FAIL] Error syncing ABIs:", error)
|
|
57
57
|
process.exit(1)
|
|
58
58
|
}
|
|
@@ -16,7 +16,7 @@ export default function Home() {
|
|
|
16
16
|
<section className="bg-gradient-to-r from-blue-50 to-indigo-50 rounded-2xl p-8 border border-blue-100">
|
|
17
17
|
<div className="max-w-3xl mx-auto text-center">
|
|
18
18
|
<div className="inline-block bg-white/80 px-4 py-2 rounded-full mb-4 text-sm font-semibold text-blue-700">
|
|
19
|
-
|
|
19
|
+
Daily Verse
|
|
20
20
|
</div>
|
|
21
21
|
<blockquote className="text-2xl font-serif italic text-gray-800 mb-4">
|
|
22
22
|
“Y todo lo que hagáis, hacedlo de corazón, como para el Señor y no para los hombres.”
|
|
@@ -92,7 +92,7 @@ export default function Home() {
|
|
|
92
92
|
</div>
|
|
93
93
|
<div className="p-4 bg-yellow-50 border border-yellow-200 rounded-lg">
|
|
94
94
|
<div className="flex items-center">
|
|
95
|
-
<div className="text-yellow-600 font-bold mr-2"
|
|
95
|
+
<div className="text-yellow-600 font-bold mr-2">[WARN]</div>
|
|
96
96
|
<p className="text-yellow-800">Warning: This action cannot be undone.</p>
|
|
97
97
|
</div>
|
|
98
98
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pasosdejesus/m",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"description": "Motor para crear y gestionar proyectos al estilo Pasos de Jesus.",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -218,7 +218,8 @@
|
|
|
218
218
|
"react-hook-form": "^7.0.0"
|
|
219
219
|
},
|
|
220
220
|
"scripts": {
|
|
221
|
-
"
|
|
221
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
222
|
+
"build": "rm -rf dist tsconfig.tsbuildinfo && npx tsc -b && perl -pi -e 'print \"#!/usr/bin/env node\\n\" if $. == 1 && $_ ne \"#!/usr/bin/env node\\n\"' dist/m.js && mkdir -p dist/templates dist/blockchain && cp -R templates/* dist/templates/",
|
|
222
223
|
"start": "node dist/m.js m:create",
|
|
223
224
|
"test": "npx vitest run",
|
|
224
225
|
"typecheck": "npx tsc -b --pretty false",
|
package/src/blockchain/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Shared deployment address resolution for Hardhat contract deployments.
|
|
6
6
|
|
|
7
|
-
>
|
|
7
|
+
> [WARN] **Monorepo v0.15.0**: Los módulos de credenciales, admin, imágenes, cache,
|
|
8
8
|
> ecosystem-addresses y slearn-info se movieron a `@pasosdejesus/mpdj/blockchain/*`.
|
|
9
9
|
> Este archivo solo documenta `deployments` que permanece en `@pasosdejesus/m`.
|
|
10
10
|
> Ver [`packages/mpdj/src/blockchain/`](../../../mpdj/src/blockchain/) para los demás.
|
package/src/debug/README.md
CHANGED
|
@@ -85,7 +85,7 @@ Any component/module ← writes via
|
|
|
85
85
|
|
|
86
86
|
### Are logs persisted?
|
|
87
87
|
|
|
88
|
-
No. Logs are volatile (buffer up to 500 entries). Use the **copy** button
|
|
88
|
+
No. Logs are volatile (buffer up to 500 entries). Use the **copy** button
|
|
89
89
|
before closing to preserve them.
|
|
90
90
|
|
|
91
91
|
### Can I use it on desktop?
|
package/src/e2e/README.md
CHANGED
|
@@ -48,8 +48,8 @@ Or via CLI:
|
|
|
48
48
|
|
|
49
49
|
### Assertions
|
|
50
50
|
```ts
|
|
51
|
-
ok(msg: string) //
|
|
52
|
-
fail(msg: string) //
|
|
51
|
+
ok(msg: string) // [OK] success
|
|
52
|
+
fail(msg: string) // [FAIL] failure (increments counter)
|
|
53
53
|
resetFailures() // Reset counter
|
|
54
54
|
summary(t0: number): number // Print summary, return failure count
|
|
55
55
|
```
|
package/src/tasks/README.md
CHANGED
|
@@ -64,15 +64,15 @@ All commands follow the same pattern:
|
|
|
64
64
|
|
|
65
65
|
| Prefijo | Significado | ¿Tiene `setup`? | Ejemplos |
|
|
66
66
|
|---------|------------|:---:|----------|
|
|
67
|
-
| `eng:` | Engine — crea tablas vía migraciones |
|
|
68
|
-
| `contract:` | Herramienta de desarrollo |
|
|
69
|
-
| `db:` | Base de datos |
|
|
70
|
-
| `wallet:` | Billetera |
|
|
71
|
-
| `ai:` | Herramientas para agentes |
|
|
72
|
-
| `m:` | Scaffolding |
|
|
73
|
-
| `req:` | Requerimientos |
|
|
74
|
-
| `env:` | Entorno |
|
|
75
|
-
| `test:` | Tests E2E |
|
|
67
|
+
| `eng:` | Engine — crea tablas vía migraciones | [OK] | `eng:credentials:setup`, `eng:wba:setup` |
|
|
68
|
+
| `contract:` | Herramienta de desarrollo | [FAIL] | `contract:test` |
|
|
69
|
+
| `db:` | Base de datos | [FAIL] | `db:migrate`, `db:create` |
|
|
70
|
+
| `wallet:` | Billetera | [FAIL] | `wallet:generate`, `wallet:send` |
|
|
71
|
+
| `ai:` | Herramientas para agentes | [FAIL] | `ai:context`, `ai:grep` |
|
|
72
|
+
| `m:` | Scaffolding | [FAIL] | `m:create`, `m:update` |
|
|
73
|
+
| `req:` | Requerimientos | [FAIL] | `req:list`, `req:sync` |
|
|
74
|
+
| `env:` | Entorno | [FAIL] | `env:diff` |
|
|
75
|
+
| `test:` | Tests E2E | [FAIL] | `test:e2e` |
|
|
76
76
|
|
|
77
77
|
**Regla**: `eng:` es para módulos que requieren instalación explícita
|
|
78
78
|
(`eng:X:setup`) porque crean estructura de base de datos. El resto son
|
package/src/test-utils/README.md
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
This directory contains generic mocking utilities for tests, designed to be reusable across multiple projects using similar stacks. These utilities have been extracted and adapted from the `learn.tg` project to become part of the `@pasosdeJesus/m` library.
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### Christian Framework
|
|
8
8
|
|
|
9
9
|
As part of "Pasos de Jesús" projects, we recognize that our work serves a higher purpose: to bring the Good News to the world through technology. The Word of God is our supreme compass (brújula suprema). We strive to act with faithful diligence, excellence, and love, remembering that our technical work ultimately serves God's kingdom.
|
|
10
10
|
|
|
11
11
|
"Whatever you do, work at it with all your heart, as working for the Lord, not for human masters" (Colossians 3:23). This includes writing tests and creating tools that help others build reliable, truthful software.
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## For users of projects generated by `m`
|
|
14
14
|
|
|
15
15
|
If you're developing a project generated with `m`, you can use these test utilities by importing them directly from the `@pasosdejesus/m` package.
|
|
16
16
|
|
|
17
|
-
>
|
|
17
|
+
> [WARN] **Vitest compatibility**: These mocks are designed for **Vitest 2.1.x**.
|
|
18
18
|
> They use `vi.hoisted()` and `vi.mock()`. For vitest 1.x, use version `0.14.x`
|
|
19
19
|
> of `@pasosdejesus/m`.
|
|
20
20
|
|
|
@@ -61,7 +61,7 @@ Esto configura automáticamente:
|
|
|
61
61
|
- **axios**: delegación a `mocks.mockAxiosGet/Post/Put/Delete/Request`
|
|
62
62
|
- **siwe**: `SiweMessage`
|
|
63
63
|
|
|
64
|
-
>
|
|
64
|
+
> [WARN] **CRÍTICO**: `vi.mock()` debe estar a **module scope** del archivo que vitest transforma.
|
|
65
65
|
> No funciona desde funciones dentro de módulos importados (como `setupMocks()`).
|
|
66
66
|
> Si usas `apiDbMocks.setupMocks()`, el `vi.mock('kysely')` interno **no se aplica**.
|
|
67
67
|
> Agrega los `vi.mock()` directamente en tu `vitest.setup.ts` o en el test file.
|
|
@@ -122,7 +122,7 @@ describe('My test', () => {
|
|
|
122
122
|
|
|
123
123
|
Check the example file included in your project: `templates/tests/test-utils.example.test.ts`.
|
|
124
124
|
|
|
125
|
-
##
|
|
125
|
+
## Structure
|
|
126
126
|
|
|
127
127
|
```
|
|
128
128
|
test-utils/
|
|
@@ -139,7 +139,7 @@ test-utils/
|
|
|
139
139
|
> (credenciales, deployments, ecosystem-addresses, slearn-info) están en
|
|
140
140
|
> `@pasosdejesus/mpdj/test-utils`. Ver [`packages/mpdj/src/test-utils/README.md`](../../mpdj/src/test-utils/README.md).
|
|
141
141
|
|
|
142
|
-
##
|
|
142
|
+
## Available Modules
|
|
143
143
|
|
|
144
144
|
### 1. `fs-mocks.ts` – Filesystem
|
|
145
145
|
|
|
@@ -181,7 +181,7 @@ beforeEach(() => {
|
|
|
181
181
|
- `createMockDb()`: Flat mock DB object with chainable methods — simple, no class needed
|
|
182
182
|
- `apiDbMocks` / `libDbMocks`: Pre-configured instances for API routes and libraries
|
|
183
183
|
|
|
184
|
-
>
|
|
184
|
+
> [WARN] **CRÍTICO**: `vi.mock()` debe estar a **module scope**. El método `setupMocks()`
|
|
185
185
|
> llama `vi.mock()` internamente pero vitest **no lo hoistea** porque está dentro de
|
|
186
186
|
> una factory en un módulo importado. Agrega los `vi.mock()` directamente:
|
|
187
187
|
|
|
@@ -377,7 +377,7 @@ viemMocks.createPublicClient.mockReturnValue({ ... })
|
|
|
377
377
|
- Mock chains are extensible; add new chains as needed
|
|
378
378
|
- **Lesson learned:** Some functions like `privateKeyToAccount` and `formatUnits` are necessary for transaction tests
|
|
379
379
|
|
|
380
|
-
##
|
|
380
|
+
## Complete Usage Examples
|
|
381
381
|
|
|
382
382
|
### Configuration for API Route Tests
|
|
383
383
|
|
|
@@ -432,7 +432,7 @@ test('renders component with wallet connection', () => {
|
|
|
432
432
|
})
|
|
433
433
|
```
|
|
434
434
|
|
|
435
|
-
##
|
|
435
|
+
## Important Lessons Learned
|
|
436
436
|
|
|
437
437
|
### 1. **Import order**
|
|
438
438
|
Radix UI mocks must be imported **before** importing any components that use them. Place `import '@pasosdejesus/m/test-utils/radix-mocks'` at the beginning of test files.
|
|
@@ -460,11 +460,11 @@ Configure mocks to simulate errors (e.g., `mockRejectedValue`) to test error flo
|
|
|
460
460
|
### 8. **`vi.mock` hoisting in Vitest (CRÍTICO)**
|
|
461
461
|
`vi.mock` calls are hoisted to the top of the **file being transformed by vitest**. NO se hoistean desde funciones dentro de módulos importados. Ejemplo:
|
|
462
462
|
```typescript
|
|
463
|
-
//
|
|
463
|
+
// [FAIL] NO FUNCIONA — el vi.mock está dentro de setupMocks() en un módulo importado
|
|
464
464
|
import { apiDbMocks } from '@pasosdejesus/m/test-utils'
|
|
465
465
|
apiDbMocks.setupMocks() // vi.mock('kysely') interno NO se aplica
|
|
466
466
|
|
|
467
|
-
//
|
|
467
|
+
// [OK] FUNCIONA — vi.mock() a module scope del archivo que vitest transforma
|
|
468
468
|
vi.mock('kysely', () => ({ Kysely: MockKysely, PostgresDialect: vi.fn(), sql: mockSql }))
|
|
469
469
|
```
|
|
470
470
|
Esto aplica a TODOS los `setupMocks()` de los test-utils. Para usar `apiDbMocks` correctamente, agrega el `vi.mock()` a module scope en tu `vitest.setup.ts` (ver ejemplo en §2).
|
|
@@ -534,14 +534,14 @@ Ensure that React versions are consistent between the test utilities package and
|
|
|
534
534
|
### 15. **Global React setup for mocks**
|
|
535
535
|
When using Radix UI mocks or other React-based mocks in Vitest setup files, set `global.React = React` before importing the mocks to ensure proper React instance sharing. This is especially important when mocks are used in `vitest.setup.ts`.
|
|
536
536
|
|
|
537
|
-
##
|
|
537
|
+
## Configuration for Other Projects
|
|
538
538
|
|
|
539
539
|
These utilities can be used in other projects with the following adaptations:
|
|
540
540
|
|
|
541
541
|
### 1. **Kysely Configuration**
|
|
542
542
|
If the project uses a different path for Kysely configuration:
|
|
543
543
|
```typescript
|
|
544
|
-
//
|
|
544
|
+
// [WARN] configPath currently non-functional due to vi.mock hoisting
|
|
545
545
|
// For different paths, configure aliases in Vite or mock manually
|
|
546
546
|
createMockKysely({ skipConfigMock: true }) // And mock the module manually
|
|
547
547
|
```
|
|
@@ -594,7 +594,7 @@ export function getMyMocks() {
|
|
|
594
594
|
}
|
|
595
595
|
```
|
|
596
596
|
|
|
597
|
-
##
|
|
597
|
+
## Contribution
|
|
598
598
|
|
|
599
599
|
The utilities are designed to be part of `@pasosdeJesus/m`. To contribute:
|
|
600
600
|
|
|
@@ -603,7 +603,7 @@ The utilities are designed to be part of `@pasosdeJesus/m`. To contribute:
|
|
|
603
603
|
3. **Test**: Ensure utilities work across multiple projects
|
|
604
604
|
4. **Christian principles**: Work with diligence, humility, and love (Colossians 3:23)
|
|
605
605
|
|
|
606
|
-
##
|
|
606
|
+
## Integration with Existing Projects
|
|
607
607
|
|
|
608
608
|
These utilities are now part of the `@pasosdeJesus/m` package and ready to use. They have been successfully integrated into the `learn.tg` project, serving as a reference implementation.
|
|
609
609
|
|
|
@@ -643,7 +643,7 @@ beforeAll(() => {
|
|
|
643
643
|
});
|
|
644
644
|
```
|
|
645
645
|
|
|
646
|
-
##
|
|
646
|
+
## License
|
|
647
647
|
|
|
648
648
|
Part of `@pasosdeJesus/m` – Utilities for "Pasos de Jesús" projects.
|
|
649
649
|
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.24;
|
|
3
|
-
|
|
4
|
-
contract MockUSDT {
|
|
5
|
-
string public constant name = "Mock USDT";
|
|
6
|
-
string public constant symbol = "MUSDT";
|
|
7
|
-
uint8 public constant decimals = 6;
|
|
8
|
-
uint256 public totalSupply;
|
|
9
|
-
|
|
10
|
-
mapping(address => uint256) public balanceOf;
|
|
11
|
-
mapping(address => mapping(address => uint256)) public allowance;
|
|
12
|
-
|
|
13
|
-
event Transfer(address indexed from, address indexed to, uint256 value);
|
|
14
|
-
event Approval(address indexed owner, address indexed spender, uint256 value);
|
|
15
|
-
|
|
16
|
-
function mint(address to, uint256 amount) external {
|
|
17
|
-
totalSupply += amount;
|
|
18
|
-
balanceOf[to] += amount;
|
|
19
|
-
emit Transfer(address(0), to, amount);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function transfer(address to, uint256 amount) external returns (bool) {
|
|
23
|
-
require(balanceOf[msg.sender] >= amount, "Insufficient balance");
|
|
24
|
-
balanceOf[msg.sender] -= amount;
|
|
25
|
-
balanceOf[to] += amount;
|
|
26
|
-
emit Transfer(msg.sender, to, amount);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
|
|
31
|
-
require(balanceOf[from] >= amount, "Insufficient balance");
|
|
32
|
-
require(allowance[from][msg.sender] >= amount, "Insufficient allowance");
|
|
33
|
-
|
|
34
|
-
balanceOf[from] -= amount;
|
|
35
|
-
balanceOf[to] += amount;
|
|
36
|
-
allowance[from][msg.sender] -= amount;
|
|
37
|
-
|
|
38
|
-
emit Transfer(from, to, amount);
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function approve(address spender, uint256 amount) external returns (bool) {
|
|
43
|
-
allowance[msg.sender][spender] = amount;
|
|
44
|
-
emit Approval(msg.sender, spender, amount);
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import { ethers } from "hardhat";
|
|
3
|
-
|
|
4
|
-
describe.skip("MockUSDT", function () {
|
|
5
|
-
it("Should deploy with correct name and symbol", async function () {
|
|
6
|
-
const MockUSDT = await ethers.getContractFactory("MockUSDT");
|
|
7
|
-
const mockUSDT = await MockUSDT.deploy();
|
|
8
|
-
await mockUSDT.waitForDeployment();
|
|
9
|
-
|
|
10
|
-
expect(await mockUSDT.name()).to.equal("Mock USDT");
|
|
11
|
-
expect(await mockUSDT.symbol()).to.equal("MUSDT");
|
|
12
|
-
expect(await mockUSDT.decimals()).to.equal(6);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("Should have initial supply of 0 tokens", async function () {
|
|
16
|
-
const MockUSDT = await ethers.getContractFactory("MockUSDT");
|
|
17
|
-
const mockUSDT = await MockUSDT.deploy();
|
|
18
|
-
await mockUSDT.waitForDeployment();
|
|
19
|
-
|
|
20
|
-
const totalSupply = await mockUSDT.totalSupply();
|
|
21
|
-
expect(totalSupply).to.equal(0);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("Should allow transfers", async function () {
|
|
25
|
-
const [owner, recipient] = await ethers.getSigners();
|
|
26
|
-
const MockUSDT = await ethers.getContractFactory("MockUSDT");
|
|
27
|
-
const mockUSDT = await MockUSDT.deploy();
|
|
28
|
-
await mockUSDT.waitForDeployment();
|
|
29
|
-
|
|
30
|
-
// Mint tokens to owner first
|
|
31
|
-
const mintAmount = ethers.parseUnits("1000", 6);
|
|
32
|
-
await mockUSDT.mint(owner.address, mintAmount);
|
|
33
|
-
|
|
34
|
-
const transferAmount = ethers.parseUnits("100", 6);
|
|
35
|
-
await mockUSDT.transfer(recipient.address, transferAmount);
|
|
36
|
-
|
|
37
|
-
const recipientBalance = await mockUSDT.balanceOf(recipient.address);
|
|
38
|
-
expect(recipientBalance).to.equal(transferAmount);
|
|
39
|
-
});
|
|
40
|
-
});
|