diff --git a/basics/counter/anchor/package.json b/basics/counter/anchor/package.json index ad95b92c4..56b0eb577 100644 --- a/basics/counter/anchor/package.json +++ b/basics/counter/anchor/package.json @@ -5,17 +5,16 @@ }, "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", "prettier": "^2.6.2", - "solana-bankrun": "^0.3.0", "ts-mocha": "^10.0.0", "typescript": "^4.3.5" }, diff --git a/basics/counter/anchor/pnpm-lock.yaml b/basics/counter/anchor/pnpm-lock.yaml index 520dfbb04..04c7df186 100644 --- a/basics/counter/anchor/pnpm-lock.yaml +++ b/basics/counter/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,9 +27,6 @@ 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 @@ -36,9 +36,6 @@ importers: prettier: specifier: ^2.6.2 version: 2.8.8 - 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) @@ -81,8 +78,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==} @@ -128,14 +144,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'} @@ -171,17 +179,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==} @@ -230,6 +231,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==} @@ -247,6 +252,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==} @@ -315,8 +324,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==} @@ -432,6 +441,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'} @@ -550,39 +599,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==} @@ -752,12 +768,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 @@ -770,11 +786,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 @@ -790,14 +807,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 @@ -810,6 +844,7 @@ snapshots: transitivePeerDependencies: - bufferutil - encoding + - typescript - utf-8-validate '@swc/helpers@0.5.12': @@ -858,12 +893,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: {} @@ -891,16 +920,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: {} @@ -957,6 +978,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 @@ -985,6 +1008,8 @@ snapshots: color-name@1.1.4: {} + commander@14.0.2: {} + commander@2.20.3: {} concat-map@0.0.1: {} @@ -1033,7 +1058,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: @@ -1142,6 +1167,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 @@ -1268,36 +1328,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/counter/anchor/tests/bankrun.test.ts b/basics/counter/anchor/tests/bankrun.test.ts deleted file mode 100644 index c3b876301..000000000 --- a/basics/counter/anchor/tests/bankrun.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { describe, it } from "node:test"; -import * as anchor from "@coral-xyz/anchor"; -import { Keypair, PublicKey } from "@solana/web3.js"; -import { BankrunProvider } from "anchor-bankrun"; -import { assert } from "chai"; -import { startAnchor } from "solana-bankrun"; -import type { CounterAnchor } from "../target/types/counter_anchor"; - -import IDL from "../target/idl/counter_anchor.json" with { type: "json" }; -const PROGRAM_ID = new PublicKey(IDL.address); - -describe("counter_anchor", async () => { - // Configure the client to use the anchor-bankrun - const context = await startAnchor( - "", - [{ name: "counter_anchor", programId: PROGRAM_ID }], - [] - ); - const provider = new BankrunProvider(context); - - const payer = provider.wallet as anchor.Wallet; - const program = new anchor.Program(IDL, provider); - - // Generate a new keypair for the counter account - const counterKeypair = new Keypair(); - - it("Initialize Counter", async () => { - await program.methods - .initializeCounter() - .accounts({ - counter: counterKeypair.publicKey, - payer: payer.publicKey, - }) - .signers([counterKeypair]) - .rpc(); - - const currentCount = await program.account.counter.fetch( - counterKeypair.publicKey - ); - - assert( - currentCount.count.toNumber() === 0, - "Expected initialized count to be 0" - ); - }); - - it("Increment Counter", async () => { - await program.methods - .increment() - .accounts({ counter: counterKeypair.publicKey }) - .rpc(); - - const currentCount = await program.account.counter.fetch( - counterKeypair.publicKey - ); - - assert(currentCount.count.toNumber() === 1, "Expected count to be 1"); - }); -}); diff --git a/basics/counter/anchor/tests/counter_anchor.ts b/basics/counter/anchor/tests/counter_anchor.ts deleted file mode 100644 index d857747aa..000000000 --- a/basics/counter/anchor/tests/counter_anchor.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type { Program } from '@coral-xyz/anchor'; -import * as anchor from '@coral-xyz/anchor'; -import { Keypair } from '@solana/web3.js'; -import { assert } from 'chai'; -import type { CounterAnchor } from '../target/types/counter_anchor'; - -describe('counter_anchor', () => { - // Configure the client to use the local cluster. - const provider = anchor.AnchorProvider.env(); - anchor.setProvider(provider); - const payer = provider.wallet as anchor.Wallet; - - const program = anchor.workspace.CounterAnchor as Program; - - // Generate a new keypair for the counter account - const counterKeypair = new Keypair(); - - it('Initialize Counter', async () => { - await program.methods - .initializeCounter() - .accounts({ - counter: counterKeypair.publicKey, - payer: payer.publicKey, - }) - .signers([counterKeypair]) - .rpc(); - - const currentCount = await program.account.counter.fetch(counterKeypair.publicKey); - - assert(currentCount.count.toNumber() === 0, 'Expected initialized count to be 0'); - }); - - it('Increment Counter', async () => { - await program.methods.increment().accounts({ counter: counterKeypair.publicKey }).rpc(); - - const currentCount = await program.account.counter.fetch(counterKeypair.publicKey); - - assert(currentCount.count.toNumber() === 1, 'Expected count to be 1'); - }); - - it('Increment Counter Again', async () => { - await program.methods.increment().accounts({ counter: counterKeypair.publicKey }).rpc(); - - const currentCount = await program.account.counter.fetch(counterKeypair.publicKey); - - assert(currentCount.count.toNumber() === 2, 'Expected count to be 2'); - }); -}); diff --git a/basics/counter/anchor/tests/litesvm.test.ts b/basics/counter/anchor/tests/litesvm.test.ts new file mode 100644 index 000000000..d3f6d8923 --- /dev/null +++ b/basics/counter/anchor/tests/litesvm.test.ts @@ -0,0 +1,121 @@ +import anchor from "@coral-xyz/anchor"; +import { + Keypair, + PublicKey, + SystemProgram, + Transaction, + TransactionInstruction, +} from "@solana/web3.js"; +import { assert } from "chai"; +import { LiteSVM } from "litesvm"; +import IDL from "../target/idl/counter_anchor.json" with { type: "json" }; + +describe("LiteSVM: Counter", () => { + const svm = new LiteSVM(); + const programId = new PublicKey(IDL.address); + const payer = Keypair.generate(); + svm.airdrop(payer.publicKey, BigInt(1000000000)); + + const coder = new anchor.BorshCoder(IDL as anchor.Idl); + const programPath = new URL( + "../target/deploy/counter_anchor.so", + import.meta.url, + ).pathname; + svm.addProgramFromFile(programId, programPath); + + /** + * Generate a new keypair for the counter account + */ + const counterKeypair = new Keypair(); + + it("Initialize Counter", () => { + /** + * Instruction data + * Create Transaction + */ + const data = coder.instruction.encode("initialize_counter", {}); + const ix = new TransactionInstruction({ + keys: [ + { pubkey: payer.publicKey, isSigner: true, isWritable: true }, + { pubkey: counterKeypair.publicKey, isSigner: true, isWritable: true }, + { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, + ], + programId, + data, + }); + + const tx = new Transaction().add(ix); + tx.feePayer = payer.publicKey; + tx.recentBlockhash = svm.latestBlockhash(); + tx.sign(payer, counterKeypair); + svm.sendTransaction(tx); + + /** + * Fetch counter account + */ + const counterAccount = svm.getAccount(counterKeypair.publicKey); + const counter = coder.accounts.decode( + "Counter", + Buffer.from(counterAccount.data), + ); + + assert.equal(counter.count, 0); + }); + + it("Increment Counter", () => { + const data = coder.instruction.encode("increment", {}); + const ix = new TransactionInstruction({ + keys: [ + { pubkey: counterKeypair.publicKey, isSigner: false, isWritable: true }, + ], + programId, + data, + }); + + const tx = new Transaction().add(ix); + tx.feePayer = payer.publicKey; + tx.recentBlockhash = svm.latestBlockhash(); + tx.sign(payer); + svm.sendTransaction(tx); + svm.expireBlockhash(); + + /** + * Fetch counter account + */ + const counterAccount = svm.getAccount(counterKeypair.publicKey); + const counter = coder.accounts.decode( + "Counter", + Buffer.from(counterAccount.data), + ); + + assert.equal(counter.count, 1); + }); + + it("Increment Counter Again", () => { + const data = coder.instruction.encode("increment", {}); + const ix = new TransactionInstruction({ + keys: [ + { pubkey: counterKeypair.publicKey, isSigner: false, isWritable: true }, + ], + programId, + data, + }); + + const tx = new Transaction().add(ix); + tx.feePayer = payer.publicKey; + tx.recentBlockhash = svm.latestBlockhash(); + tx.sign(payer); + svm.sendTransaction(tx); + + /** + * Fetch counter account + */ + const counterAccount = svm.getAccount(counterKeypair.publicKey); + const counter = coder.accounts.decode( + "Counter", + Buffer.from(counterAccount.data), + ); + + assert.equal(counter.count, 2); + }); +}); diff --git a/basics/counter/anchor/tests/test.ts b/basics/counter/anchor/tests/test.ts new file mode 100644 index 000000000..06909a3c8 --- /dev/null +++ b/basics/counter/anchor/tests/test.ts @@ -0,0 +1,63 @@ +import type { Program } from "@coral-xyz/anchor"; +import * as anchor from "@coral-xyz/anchor"; +import { Keypair } from "@solana/web3.js"; +import { assert } from "chai"; +import type { CounterAnchor } from "../target/types/counter_anchor.ts"; + +describe("Anchor: Counter", () => { + // Configure the client to use the local cluster. + const provider = anchor.AnchorProvider.env(); + anchor.setProvider(provider); + const payer = provider.wallet as anchor.Wallet; + + const program = anchor.workspace.CounterAnchor as Program; + + // Generate a new keypair for the counter account + const counterKeypair = new Keypair(); + + it("Initialize Counter", async () => { + await program.methods + .initializeCounter() + .accounts({ + counter: counterKeypair.publicKey, + payer: payer.publicKey, + }) + .signers([counterKeypair]) + .rpc(); + + const currentCount = await program.account.counter.fetch( + counterKeypair.publicKey, + ); + + assert( + currentCount.count.toNumber() === 0, + "Expected initialized count to be 0", + ); + }); + + it("Increment Counter", async () => { + await program.methods + .increment() + .accounts({ counter: counterKeypair.publicKey }) + .rpc(); + + const currentCount = await program.account.counter.fetch( + counterKeypair.publicKey, + ); + + assert(currentCount.count.toNumber() === 1, "Expected count to be 1"); + }); + + it("Increment Counter Again", async () => { + await program.methods + .increment() + .accounts({ counter: counterKeypair.publicKey }) + .rpc(); + + const currentCount = await program.account.counter.fetch( + counterKeypair.publicKey, + ); + + assert(currentCount.count.toNumber() === 2, "Expected count to be 2"); + }); +}); diff --git a/basics/counter/anchor/tsconfig.json b/basics/counter/anchor/tsconfig.json index cd5d2e3d0..fdf5c04de 100644 --- a/basics/counter/anchor/tsconfig.json +++ b/basics/counter/anchor/tsconfig.json @@ -1,10 +1,10 @@ { - "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": ["es2020"], + "module": "nodenext", + "target": "es2020", + "esModuleInterop": true + } }