diff --git a/basics/checking-accounts/anchor/Anchor.toml b/basics/checking-accounts/anchor/Anchor.toml index f71235ba3..a4df75902 100644 --- a/basics/checking-accounts/anchor/Anchor.toml +++ b/basics/checking-accounts/anchor/Anchor.toml @@ -12,3 +12,4 @@ wallet = "~/.config/solana/id.json" [scripts] test = "pnpm ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts" +litesvm-test = "node --test tests/litesvm.test.ts" \ No newline at end of file diff --git a/basics/checking-accounts/anchor/package.json b/basics/checking-accounts/anchor/package.json index 7865c8c24..9d86fae3d 100644 --- a/basics/checking-accounts/anchor/package.json +++ b/basics/checking-accounts/anchor/package.json @@ -2,16 +2,15 @@ "type": "module", "dependencies": { "@coral-xyz/anchor": "0.32.1", - "@solana/web3.js": "^1.95.2" + "@solana/web3.js": "^1.98.4", + "litesvm": "^0.4.0" }, "devDependencies": { "@types/bn.js": "^5.1.0", "@types/chai": "^4.3.0", "@types/mocha": "^9.0.0", - "anchor-bankrun": "^0.4.0", "chai": "^4.3.4", "mocha": "^9.0.3", - "solana-bankrun": "^0.3.0", "ts-mocha": "^10.0.0", "typescript": "^4.3.5" } diff --git a/basics/checking-accounts/anchor/pnpm-lock.yaml b/basics/checking-accounts/anchor/pnpm-lock.yaml index aae81ea51..a6dc09428 100644 --- a/basics/checking-accounts/anchor/pnpm-lock.yaml +++ b/basics/checking-accounts/anchor/pnpm-lock.yaml @@ -10,10 +10,13 @@ importers: dependencies: '@coral-xyz/anchor': specifier: 0.32.1 - version: 0.32.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) + version: 0.32.1(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10) '@solana/web3.js': - specifier: ^1.95.2 - version: 1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10) + specifier: ^1.98.4 + version: 1.98.4(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10) + litesvm: + specifier: ^0.4.0 + version: 0.4.0(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10) devDependencies: '@types/bn.js': specifier: ^5.1.0 @@ -24,18 +27,12 @@ importers: '@types/mocha': specifier: ^9.0.0 version: 9.1.1 - anchor-bankrun: - specifier: ^0.4.0 - version: 0.4.0(@coral-xyz/anchor@0.32.1(bufferutil@4.0.8)(utf-8-validate@5.0.10))(@solana/web3.js@1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10))(solana-bankrun@0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)) chai: specifier: ^4.3.4 version: 4.4.1 mocha: specifier: ^9.0.3 version: 9.2.2 - solana-bankrun: - specifier: ^0.3.0 - version: 0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) ts-mocha: specifier: ^10.0.0 version: 10.0.0(mocha@9.2.2) @@ -78,8 +75,27 @@ packages: resolution: {integrity: sha512-E1ImOIAD1tBZFRdjeM4/pzTiTApC0AOBGwyAMS4fwIodCWArzJ3DWdoh8cKxeFM2fElkxBh2Aqts1BPC373rHA==} engines: {node: '>=5.10'} - '@solana/web3.js@1.95.2': - resolution: {integrity: sha512-SjlHp0G4qhuhkQQc+YXdGkI8EerCqwxvgytMgBpzMUQTafrkNant3e7pgilBGgjy/iM40ICvWBLgASTPMrQU7w==} + '@solana/codecs-core@2.3.0': + resolution: {integrity: sha512-oG+VZzN6YhBHIoSKgS5ESM9VIGzhWjEHEGNPSibiDTxFhsFWxNaz8LbMDPjBUE69r9wmdGLkrQ+wVPbnJcZPvw==} + engines: {node: '>=20.18.0'} + peerDependencies: + typescript: '>=5.3.3' + + '@solana/codecs-numbers@2.3.0': + resolution: {integrity: sha512-jFvvwKJKffvG7Iz9dmN51OGB7JBcy2CJ6Xf3NqD/VP90xak66m/Lg48T01u5IQ/hc15mChVHiBm+HHuOFDUrQg==} + engines: {node: '>=20.18.0'} + peerDependencies: + typescript: '>=5.3.3' + + '@solana/errors@2.3.0': + resolution: {integrity: sha512-66RI9MAbwYV0UtP7kGcTBVLxJgUxoZGm8Fbc0ah+lGiAw17Gugco6+9GrJCV83VyF2mDWyYnYM9qdI3yjgpnaQ==} + engines: {node: '>=20.18.0'} + hasBin: true + peerDependencies: + typescript: '>=5.3.3' + + '@solana/web3.js@1.98.4': + resolution: {integrity: sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw==} '@swc/helpers@0.5.12': resolution: {integrity: sha512-KMZNXiGibsW9kvZAO1Pam2JPTDBm+KSHMMHWdsyI/1DbIZjT2A6Gy3hblVXUMEDvUAKq+e0vL0X0o54owWji7g==} @@ -125,14 +141,6 @@ packages: resolution: {integrity: sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==} engines: {node: '>= 8.0.0'} - anchor-bankrun@0.4.0: - resolution: {integrity: sha512-s+K7E0IGAlmkhuo8nbiqVsQf2yJ+3l9GjNQJSmkRDe25dQj4Yef9rJh77FH6EQ5H6yQYfzuhgm/5GD6JMjdTZg==} - engines: {node: '>= 10'} - peerDependencies: - '@coral-xyz/anchor': ^0.30.0 - '@solana/web3.js': ^1.78.4 - solana-bankrun: ^0.2.0 - ansi-colors@4.1.1: resolution: {integrity: sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==} engines: {node: '>=6'} @@ -168,17 +176,10 @@ packages: base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} - bigint-buffer@1.1.5: - resolution: {integrity: sha512-trfYco6AoZ+rKhKnxA0hgX0HAbVP/s808/EuDSe2JDzUnCp/xAsli35Orvk67UrTEcwuxZqYZDmfA2RXJgxVvA==} - engines: {node: '>= 10.0.0'} - binary-extensions@2.3.0: resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==} engines: {node: '>=8'} - bindings@1.5.0: - resolution: {integrity: sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==} - bn.js@5.2.1: resolution: {integrity: sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==} @@ -227,6 +228,10 @@ packages: resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} engines: {node: '>=10'} + chalk@5.6.2: + resolution: {integrity: sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + check-error@1.0.3: resolution: {integrity: sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==} @@ -244,6 +249,10 @@ packages: color-name@1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + commander@14.0.2: + resolution: {integrity: sha512-TywoWNNRbhoD0BXs1P3ZEScW8W5iKrnbithIl0YH+uCmBd0QpPOA8yc82DS3BIE5Ma6FnBVUsJ7wVUDz4dvOWQ==} + engines: {node: '>=20'} + commander@2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} @@ -312,8 +321,8 @@ packages: fast-stable-stringify@1.0.0: resolution: {integrity: sha512-wpYMUmFu5f00Sm0cj2pfivpmawLZ0NKdviQ4w9zJeR8JVtOpOxHmLaJuj0vxvGqMJQWyP/COUkF75/57OKyRag==} - file-uri-to-path@1.0.0: - resolution: {integrity: sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==} + fastestsmallesttextencoderdecoder@1.0.22: + resolution: {integrity: sha512-Pb8d48e+oIuY4MaM64Cd7OW1gt4nxCHs7/ddPPZ/Ic3sg8yVGM7O9wDvZ7us6ScaUupzM+pfBolwtYhN1IxBIw==} fill-range@7.0.1: resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} @@ -429,6 +438,46 @@ packages: resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==} engines: {'0': node >= 0.2.0} + litesvm-darwin-arm64@0.4.0: + resolution: {integrity: sha512-LN6iZcUQ6Xi5KO/7yJBYSALjjDCI/s/s2PgV3BqM4dpeBaLz+fXX/+qgMcBgpEVgEdEmhelux+WtAMkbEzJfrA==} + engines: {node: '>= 20'} + cpu: [arm64] + os: [darwin] + + litesvm-darwin-x64@0.4.0: + resolution: {integrity: sha512-3ltogKQdle8LbakVqoB6plxaNwp6Vb3tnkqa3G5mAvvZNorB2iumThDaTZ381Knl69t566LZm+g/VDZwYfsfhA==} + engines: {node: '>= 20'} + cpu: [x64] + os: [darwin] + + litesvm-linux-arm64-gnu@0.4.0: + resolution: {integrity: sha512-SWlcRUqkXCMgLoDX/Wqr/S1lff+ggVI9f0YrRJMraxtEyApxutAoW2AWw4tvo6DsEgNwjxgsZOAwnE6bQBv8CA==} + engines: {node: '>= 20'} + cpu: [arm64] + os: [linux] + + litesvm-linux-arm64-musl@0.4.0: + resolution: {integrity: sha512-YMMqwEWJUSWwL0Rwp8dFwl3jvgNU21eI7Qc+BpH9u2yeIRYQTn3rNGDnsK8v3QIZPHQdMo7NrPhzk4XoB1aKPg==} + engines: {node: '>= 20'} + cpu: [arm64] + os: [linux] + + litesvm-linux-x64-gnu@0.4.0: + resolution: {integrity: sha512-brZ3tFABDVQEYCgci7AO8iVYLw10UXVo97/lpTy75bTzNoqkggg8wFQOrbgCdb9NRwt06Y4Zf8cpIZAoDQq2mw==} + engines: {node: '>= 20'} + cpu: [x64] + os: [linux] + + litesvm-linux-x64-musl@0.4.0: + resolution: {integrity: sha512-D98qdIOuWg4fOewIIiH1D23AtM4I7/3vLKXIL8uQz06D5ev5fsBzNp2gM7libAywTkCYy/u666xgD6PsWhrTaw==} + engines: {node: '>= 20'} + cpu: [x64] + os: [linux] + + litesvm@0.4.0: + resolution: {integrity: sha512-ySr5mB2ap4SzJpmVR2I5+gjzTH8NJbkg7DYPormzA2U9F4LhfvTTrD17X/k5N3Bn4b5Db6/CwSyX2qc0HrJtNA==} + engines: {node: '>= 20'} + locate-path@6.0.0: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} @@ -542,39 +591,6 @@ packages: serialize-javascript@6.0.0: resolution: {integrity: sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==} - solana-bankrun-darwin-arm64@0.3.0: - resolution: {integrity: sha512-+NbDncf0U6l3knuacRBiqpjZ2DSp+5lZaAU518gH7/x6qubbui/d000STaIBK+uNTPBS/AL/bCN+7PkXqmA3lA==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [darwin] - - solana-bankrun-darwin-universal@0.3.0: - resolution: {integrity: sha512-1/F0xdMa4qvc5o6z16FCCbZ5jbdvKvxpx5kyPcMWRiRPwyvi+zltMxciPAYMlg3wslQqGz88uFhrBEzq2eTumQ==} - engines: {node: '>= 10'} - os: [darwin] - - solana-bankrun-darwin-x64@0.3.0: - resolution: {integrity: sha512-U6CANjkmMl+lgNA7UH0GKs5V7LtVIUDzJBZefGGqLfqUNv3EjA/PrrToM0hAOWJgkxSwdz6zW+p5sw5FmnbXtg==} - engines: {node: '>= 10'} - cpu: [x64] - os: [darwin] - - solana-bankrun-linux-x64-gnu@0.3.0: - resolution: {integrity: sha512-qJSkCFs0k2n4XtTnyxGMiZsuqO2TiqTYgWjQ+3mZhGNUAMys/Vq8bd7/SyBm6RR7EfVuRXRxZvh+F8oKZ77V4w==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - - solana-bankrun-linux-x64-musl@0.3.0: - resolution: {integrity: sha512-xsS2CS2xb1Sw4ivNXM0gPz/qpW9BX0neSvt/pnok5L330Nu9xlTnKAY8FhzzqOP9P9sJlGRM787Y6d0yYwt6xQ==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - - solana-bankrun@0.3.0: - resolution: {integrity: sha512-YkH7sa8TB/AoRPzG17CXJtYsRIQHEkEqGLz1Vwc13taXhDBkjO7z6NI5JYw7n0ybRymDHwMYTc7sd+5J40TyVQ==} - engines: {node: '>= 10'} - source-map-support@0.5.21: resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} @@ -744,12 +760,12 @@ snapshots: '@coral-xyz/anchor-errors@0.31.1': {} - '@coral-xyz/anchor@0.32.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)': + '@coral-xyz/anchor@0.32.1(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10)': dependencies: '@coral-xyz/anchor-errors': 0.31.1 - '@coral-xyz/borsh': 0.31.1(@solana/web3.js@1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10)) + '@coral-xyz/borsh': 0.31.1(@solana/web3.js@1.98.4(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10)) '@noble/hashes': 1.8.0 - '@solana/web3.js': 1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@solana/web3.js': 1.98.4(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10) bn.js: 5.2.2 bs58: 4.0.1 buffer-layout: 1.2.2 @@ -762,11 +778,12 @@ snapshots: transitivePeerDependencies: - bufferutil - encoding + - typescript - utf-8-validate - '@coral-xyz/borsh@0.31.1(@solana/web3.js@1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10))': + '@coral-xyz/borsh@0.31.1(@solana/web3.js@1.98.4(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10))': dependencies: - '@solana/web3.js': 1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10) + '@solana/web3.js': 1.98.4(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10) bn.js: 5.2.2 buffer-layout: 1.2.2 @@ -782,14 +799,31 @@ snapshots: dependencies: buffer: 6.0.3 - '@solana/web3.js@1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10)': + '@solana/codecs-core@2.3.0(typescript@4.9.5)': + dependencies: + '@solana/errors': 2.3.0(typescript@4.9.5) + typescript: 4.9.5 + + '@solana/codecs-numbers@2.3.0(typescript@4.9.5)': + dependencies: + '@solana/codecs-core': 2.3.0(typescript@4.9.5) + '@solana/errors': 2.3.0(typescript@4.9.5) + typescript: 4.9.5 + + '@solana/errors@2.3.0(typescript@4.9.5)': + dependencies: + chalk: 5.6.2 + commander: 14.0.2 + typescript: 4.9.5 + + '@solana/web3.js@1.98.4(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10)': dependencies: '@babel/runtime': 7.25.0 '@noble/curves': 1.4.2 '@noble/hashes': 1.4.0 '@solana/buffer-layout': 4.0.1 + '@solana/codecs-numbers': 2.3.0(typescript@4.9.5) agentkeepalive: 4.5.0 - bigint-buffer: 1.1.5 bn.js: 5.2.1 borsh: 0.7.0 bs58: 4.0.1 @@ -802,6 +836,7 @@ snapshots: transitivePeerDependencies: - bufferutil - encoding + - typescript - utf-8-validate '@swc/helpers@0.5.12': @@ -850,12 +885,6 @@ snapshots: dependencies: humanize-ms: 1.2.1 - anchor-bankrun@0.4.0(@coral-xyz/anchor@0.32.1(bufferutil@4.0.8)(utf-8-validate@5.0.10))(@solana/web3.js@1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10))(solana-bankrun@0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)): - dependencies: - '@coral-xyz/anchor': 0.32.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) - '@solana/web3.js': 1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10) - solana-bankrun: 0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) - ansi-colors@4.1.1: {} ansi-regex@5.0.1: {} @@ -883,16 +912,8 @@ snapshots: base64-js@1.5.1: {} - bigint-buffer@1.1.5: - dependencies: - bindings: 1.5.0 - binary-extensions@2.3.0: {} - bindings@1.5.0: - dependencies: - file-uri-to-path: 1.0.0 - bn.js@5.2.1: {} bn.js@5.2.2: {} @@ -949,6 +970,8 @@ snapshots: ansi-styles: 4.3.0 supports-color: 7.2.0 + chalk@5.6.2: {} + check-error@1.0.3: dependencies: get-func-name: 2.0.2 @@ -977,6 +1000,8 @@ snapshots: color-name@1.1.4: {} + commander@14.0.2: {} + commander@2.20.3: {} concat-map@0.0.1: {} @@ -1025,7 +1050,7 @@ snapshots: fast-stable-stringify@1.0.0: {} - file-uri-to-path@1.0.0: {} + fastestsmallesttextencoderdecoder@1.0.22: {} fill-range@7.0.1: dependencies: @@ -1134,6 +1159,41 @@ snapshots: jsonparse@1.3.1: {} + litesvm-darwin-arm64@0.4.0: + optional: true + + litesvm-darwin-x64@0.4.0: + optional: true + + litesvm-linux-arm64-gnu@0.4.0: + optional: true + + litesvm-linux-arm64-musl@0.4.0: + optional: true + + litesvm-linux-x64-gnu@0.4.0: + optional: true + + litesvm-linux-x64-musl@0.4.0: + optional: true + + litesvm@0.4.0(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10): + dependencies: + '@solana/web3.js': 1.98.4(bufferutil@4.0.8)(typescript@4.9.5)(utf-8-validate@5.0.10) + fastestsmallesttextencoderdecoder: 1.0.22 + optionalDependencies: + litesvm-darwin-arm64: 0.4.0 + litesvm-darwin-x64: 0.4.0 + litesvm-linux-arm64-gnu: 0.4.0 + litesvm-linux-arm64-musl: 0.4.0 + litesvm-linux-x64-gnu: 0.4.0 + litesvm-linux-x64-musl: 0.4.0 + transitivePeerDependencies: + - bufferutil + - encoding + - typescript + - utf-8-validate + locate-path@6.0.0: dependencies: p-locate: 5.0.0 @@ -1258,36 +1318,6 @@ snapshots: dependencies: randombytes: 2.1.0 - solana-bankrun-darwin-arm64@0.3.0: - optional: true - - solana-bankrun-darwin-universal@0.3.0: - optional: true - - solana-bankrun-darwin-x64@0.3.0: - optional: true - - solana-bankrun-linux-x64-gnu@0.3.0: - optional: true - - solana-bankrun-linux-x64-musl@0.3.0: - optional: true - - solana-bankrun@0.3.0(bufferutil@4.0.8)(utf-8-validate@5.0.10): - dependencies: - '@solana/web3.js': 1.95.2(bufferutil@4.0.8)(utf-8-validate@5.0.10) - bs58: 4.0.1 - optionalDependencies: - solana-bankrun-darwin-arm64: 0.3.0 - solana-bankrun-darwin-universal: 0.3.0 - solana-bankrun-darwin-x64: 0.3.0 - solana-bankrun-linux-x64-gnu: 0.3.0 - solana-bankrun-linux-x64-musl: 0.3.0 - transitivePeerDependencies: - - bufferutil - - encoding - - utf-8-validate - source-map-support@0.5.21: dependencies: buffer-from: 1.1.2 diff --git a/basics/checking-accounts/anchor/tests/bankrun.test.ts b/basics/checking-accounts/anchor/tests/bankrun.test.ts deleted file mode 100644 index e3e089cd7..000000000 --- a/basics/checking-accounts/anchor/tests/bankrun.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { describe, it } from "node:test"; -import * as anchor from "@coral-xyz/anchor"; -import { - Keypair, - PublicKey, - SystemProgram, - Transaction, -} from "@solana/web3.js"; -import { BankrunProvider } from "anchor-bankrun"; -import { startAnchor } from "solana-bankrun"; -import type { CheckingAccountProgram } from "../target/types/checking_account_program"; - -import IDL from "../target/idl/checking_account_program.json" with { - type: "json", -}; -const PROGRAM_ID = new PublicKey(IDL.address); - -describe("Bankrun example", async () => { - const context = await startAnchor( - "", - [{ name: "checking_account_program", programId: PROGRAM_ID }], - [], - ); - const provider = new BankrunProvider(context); - - const wallet = provider.wallet as anchor.Wallet; - const program = new anchor.Program(IDL, provider); - const client = context.banksClient; - - // We'll create this ahead of time. - // Our program will try to modify it. - const accountToChange = new Keypair(); - // Our program will create this. - const accountToCreate = new Keypair(); - - it("Create an account owned by our program", async () => { - const instruction = SystemProgram.createAccount({ - fromPubkey: provider.wallet.publicKey, - newAccountPubkey: accountToChange.publicKey, - lamports: await provider.connection.getMinimumBalanceForRentExemption(0), - space: 0, - programId: program.programId, // Our program - }); - - const transaction = new Transaction(); - const blockhash = context.lastBlockhash; - - transaction.recentBlockhash = blockhash; - transaction.add(instruction).sign(wallet.payer, accountToChange); - await client.processTransaction(transaction); - }); - - it("Check accounts", async () => { - await program.methods - .checkAccounts() - .accounts({ - payer: wallet.publicKey, - accountToCreate: accountToCreate.publicKey, - accountToChange: accountToChange.publicKey, - }) - .rpc(); - }); -}); diff --git a/basics/checking-accounts/anchor/tests/litesvm.test.ts b/basics/checking-accounts/anchor/tests/litesvm.test.ts new file mode 100644 index 000000000..0051022b8 --- /dev/null +++ b/basics/checking-accounts/anchor/tests/litesvm.test.ts @@ -0,0 +1,97 @@ +import assert from "node:assert/strict"; +import { describe, it } from "node:test"; +import { + Keypair, + LAMPORTS_PER_SOL, + PublicKey, + SystemProgram, + Transaction, + TransactionInstruction, +} from "@solana/web3.js"; +import { LiteSVM } from "litesvm"; + +import IDL from "../target/idl/checking_account_program.json" with { + type: "json", +}; + +describe("LiteSVM: Checking accounts", () => { + const litesvm = new LiteSVM(); + + const programId = new PublicKey(IDL.address); + const payer = Keypair.generate(); + + const programPath = new URL( + "../target/deploy/checking_account_program.so", + import.meta.url, + ).pathname; + litesvm.addProgramFromFile(programId, programPath); + + litesvm.airdrop(payer.publicKey, BigInt(5 * LAMPORTS_PER_SOL)); + + // We'll create this ahead of time. + // Our program will try to modify it. + const accountToChange = new Keypair(); + // Our program will create this. + const accountToCreate = new Keypair(); + + it("Create an account owned by our program", () => { + const instruction = SystemProgram.createAccount({ + fromPubkey: payer.publicKey, + newAccountPubkey: accountToChange.publicKey, + lamports: Number(litesvm.getRent().minimumBalance(0n)), + space: 0, + programId: programId, // Our program + }); + + const tx = new Transaction(); + tx.recentBlockhash = litesvm.latestBlockhash(); + tx.add(instruction); + tx.feePayer = payer.publicKey; + tx.sign(accountToChange, payer); + + const res = litesvm.sendTransaction(tx); + assert.equal( + res.toString().includes("AccountNotFound"), + false, + "Expected account not found error", + ); + }); + + it("Check accounts", () => { + const instruction = new TransactionInstruction({ + keys: [ + { pubkey: payer.publicKey, isSigner: true, isWritable: false }, + { + pubkey: accountToCreate.publicKey, + isSigner: false, + isWritable: true, + }, + { + pubkey: accountToChange.publicKey, + isSigner: false, + isWritable: true, + }, + { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, + ], + programId: programId, + + data: Buffer.from( + IDL.instructions.find((i) => i.name === "check_accounts") + ?.discriminator, + ), + }); + + const tx = new Transaction(); + tx.recentBlockhash = litesvm.latestBlockhash(); + tx.add(instruction); + tx.feePayer = payer.publicKey; + tx.sign(payer); + + const res = litesvm.sendTransaction(tx); + assert.equal( + res.toString().includes("FailedTransactionMetadata"), + false, + " No account found error", + ); + }); +}); diff --git a/basics/checking-accounts/anchor/tsconfig.json b/basics/checking-accounts/anchor/tsconfig.json index cd5d2e3d0..e02fd079d 100644 --- a/basics/checking-accounts/anchor/tsconfig.json +++ b/basics/checking-accounts/anchor/tsconfig.json @@ -1,10 +1,11 @@ { - "compilerOptions": { - "types": ["mocha", "chai"], - "typeRoots": ["./node_modules/@types"], - "lib": ["es2015"], - "module": "commonjs", - "target": "es6", - "esModuleInterop": true - } + "compilerOptions": { + "types": ["mocha", "chai"], + "typeRoots": ["./node_modules/@types"], + "lib": ["es2015"], + "module": "nodenext", + "target": "es2020", + "esModuleInterop": true, + "resolveJsonModule": true + } }