diff --git a/basics/favorites/anchor/Anchor.toml b/basics/favorites/anchor/Anchor.toml index 4122ebdb8..94bbb8a8b 100644 --- a/basics/favorites/anchor/Anchor.toml +++ b/basics/favorites/anchor/Anchor.toml @@ -15,4 +15,4 @@ cluster = "Localnet" wallet = "~/.config/solana/id.json" [scripts] -test = "pnpm ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.test.ts" +test = "pnpm ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts" diff --git a/basics/favorites/anchor/package.json b/basics/favorites/anchor/package.json index 13e04d66f..31041ff82 100644 --- a/basics/favorites/anchor/package.json +++ b/basics/favorites/anchor/package.json @@ -6,19 +6,17 @@ }, "dependencies": { "@coral-xyz/anchor": "0.32.1", - "@solana-developers/helpers": "^2.0.0", - "@solana/web3.js": "^1.95.2" + "@solana/web3.js": "^1.98.4", + "litesvm": "^0.4.0" }, "license": "MIT", "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/favorites/anchor/pnpm-lock.yaml b/basics/favorites/anchor/pnpm-lock.yaml index 7f2e738ca..2f0621b94 100644 --- a/basics/favorites/anchor/pnpm-lock.yaml +++ b/basics/favorites/anchor/pnpm-lock.yaml @@ -10,13 +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) - '@solana-developers/helpers': - specifier: ^2.0.0 - version: 2.3.0(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 @@ -27,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 @@ -39,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) @@ -80,15 +74,31 @@ packages: resolution: {integrity: sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==} engines: {node: ^14.21.3 || >=16} - '@solana-developers/helpers@2.3.0': - resolution: {integrity: sha512-OVdm/RJ9OMI23AnBYX/8UWuNtHRUxaXRUzhXo4WRtXYPHdQ+jTFS2TsjKSJ/F3a0kUZ6nN0b5TekFZvqYF0Qdg==} - '@solana/buffer-layout@4.0.1': 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.11': resolution: {integrity: sha512-YNlnKRWF2sVojTpIyzwou9XoTNbzbzONwRhOoniEioF1AtaitTvVZblaQRrAzChWQ1bLYyYSWzM18y4WwgzJ+A==} @@ -134,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'} @@ -174,23 +176,13 @@ packages: base-x@3.0.9: resolution: {integrity: sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==} - base-x@4.0.0: - resolution: {integrity: sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==} - 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==} @@ -213,9 +205,6 @@ packages: bs58@4.0.1: resolution: {integrity: sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==} - bs58@5.0.0: - resolution: {integrity: sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==} - buffer-from@1.1.2: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} @@ -242,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==} @@ -259,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==} @@ -297,10 +294,6 @@ packages: resolution: {integrity: sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==} engines: {node: '>=0.3.1'} - dotenv@16.4.5: - resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==} - engines: {node: '>=12'} - emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -331,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.1.1: resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==} @@ -450,6 +443,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'} @@ -568,39 +601,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==} @@ -770,12 +770,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 @@ -788,11 +788,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 @@ -804,28 +805,35 @@ snapshots: '@noble/hashes@1.8.0': {} - '@solana-developers/helpers@2.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: 5.0.0 - dotenv: 16.4.5 - transitivePeerDependencies: - - bufferutil - - encoding - - utf-8-validate - '@solana/buffer-layout@4.0.1': 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 @@ -838,6 +846,7 @@ snapshots: transitivePeerDependencies: - bufferutil - encoding + - typescript - utf-8-validate '@swc/helpers@0.5.11': @@ -886,12 +895,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: {} @@ -917,20 +920,10 @@ snapshots: dependencies: safe-buffer: 5.2.1 - base-x@4.0.0: {} - 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: {} @@ -956,10 +949,6 @@ snapshots: dependencies: base-x: 3.0.9 - bs58@5.0.0: - dependencies: - base-x: 4.0.0 - buffer-from@1.1.2: {} buffer-layout@1.2.2: {} @@ -991,6 +980,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 @@ -1019,6 +1010,8 @@ snapshots: color-name@1.1.4: {} + commander@14.0.2: {} + commander@2.20.3: {} concat-map@0.0.1: {} @@ -1047,8 +1040,6 @@ snapshots: diff@5.0.0: {} - dotenv@16.4.5: {} - emoji-regex@8.0.0: {} es6-promise@4.2.8: {} @@ -1069,7 +1060,7 @@ snapshots: fast-stable-stringify@1.0.0: {} - file-uri-to-path@1.0.0: {} + fastestsmallesttextencoderdecoder@1.0.22: {} fill-range@7.1.1: dependencies: @@ -1178,6 +1169,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 @@ -1304,36 +1330,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/favorites/anchor/tests/favorites-bankrun.test.ts b/basics/favorites/anchor/tests/favorites-bankrun.test.ts deleted file mode 100644 index 5a1056fa3..000000000 --- a/basics/favorites/anchor/tests/favorites-bankrun.test.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { describe, it } from "node:test"; -import * as anchor from "@coral-xyz/anchor"; -import { PublicKey } from "@solana/web3.js"; -import { getCustomErrorMessage } from "@solana-developers/helpers"; -import { BankrunProvider } from "anchor-bankrun"; -import { assert } from "chai"; -import { startAnchor } from "solana-bankrun"; -import type { Favorites } from "../target/types/favorites"; -import { systemProgramErrors } from "./system-errors"; - -const web3 = anchor.web3; -import IDL from "../target/idl/favorites.json"; -const PROGRAM_ID = new PublicKey(IDL.address); - -describe("Favorites Bankrun", async () => { - // Use the cluster and the keypair from Anchor.toml - // Load programs into anchor-bankrun - const context = await startAnchor( - "", - [{ name: "favorites", programId: PROGRAM_ID }], - [], - ); - const provider = new BankrunProvider(context); - anchor.setProvider(provider); - const user = (provider.wallet as anchor.Wallet).payer; - const someRandomGuy = anchor.web3.Keypair.generate(); - - const program = new anchor.Program(IDL, provider); - - // Here's what we want to write to the blockchain - const favoriteNumber = new anchor.BN(23); - const favoriteColor = "purple"; - const favoriteHobbies = ["skiing", "skydiving", "biking"]; - - // We don't need to airdrop if we're using the local cluster - // because the local cluster gives us 1,000,000 SOL - const balance = await context.banksClient.getBalance(user.publicKey); - const balanceInSOL = balance / BigInt(web3.LAMPORTS_PER_SOL); - const formattedBalance = new Intl.NumberFormat().format(balanceInSOL); - console.log(`Balance: ${formattedBalance} SOL`); - - it("Writes our favorites to the blockchain", async () => { - await program.methods - // set_favourites in Rust becomes setFavorites in TypeScript - .setFavorites(favoriteNumber, favoriteColor, favoriteHobbies) - // Sign the transaction - .signers([user]) - // Send the transaction to the cluster or RPC - .rpc(); - - // Find the PDA for the user's favorites - const favoritesPdaAndBump = web3.PublicKey.findProgramAddressSync( - [Buffer.from("favorites"), user.publicKey.toBuffer()], - program.programId, - ); - const favoritesPda = favoritesPdaAndBump[0]; - const dataFromPda = await program.account.favorites.fetch(favoritesPda); - // And make sure it matches! - assert.equal(dataFromPda.color, favoriteColor); - // A little extra work to make sure the BNs are equal - assert.equal(dataFromPda.number.toString(), favoriteNumber.toString()); - // And check the hobbies too - assert.deepEqual(dataFromPda.hobbies, favoriteHobbies); - }); - - it("Updates the favorites", async () => { - const newFavoriteHobbies = ["skiing", "skydiving", "biking", "swimming"]; - try { - await program.methods - .setFavorites(favoriteNumber, favoriteColor, newFavoriteHobbies) - .signers([user]) - .rpc(); - } catch (error) { - console.error((error as Error).message); - const customErrorMessage = getCustomErrorMessage( - systemProgramErrors, - error, - ); - throw new Error(customErrorMessage); - } - }); - - it("Rejects transactions from unauthorized signers", async () => { - try { - await program.methods - // set_favourites in Rust becomes setFavorites in TypeScript - .setFavorites(favoriteNumber, favoriteColor, favoriteHobbies) - // Sign the transaction - .signers([someRandomGuy]) - // Send the transaction to the cluster or RPC - .rpc(); - } catch (error) { - const errorMessage = (error as Error).message; - assert.isTrue(errorMessage.includes("unknown signer")); - } - }); -}); diff --git a/basics/favorites/anchor/tests/favorites.test.ts b/basics/favorites/anchor/tests/favorites.test.ts deleted file mode 100644 index 9c5fe4024..000000000 --- a/basics/favorites/anchor/tests/favorites.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -import type { Program } from '@coral-xyz/anchor'; -import * as anchor from '@coral-xyz/anchor'; -import { getCustomErrorMessage } from '@solana-developers/helpers'; -import { assert } from 'chai'; -import type { Favorites } from '../target/types/favorites'; -import { systemProgramErrors } from './system-errors'; - -const web3 = anchor.web3; - -describe('Favorites', () => { - // Use the cluster and the keypair from Anchor.toml - const provider = anchor.AnchorProvider.env(); - anchor.setProvider(provider); - - // See https://github.com/coral-xyz/anchor/issues/3122 - const user = (provider.wallet as anchor.Wallet).payer; - const someRandomGuy = anchor.web3.Keypair.generate(); - const program = anchor.workspace.Favorites as Program; - - // Here's what we want to write to the blockchain - const favoriteNumber = new anchor.BN(23); - const favoriteColor = 'purple'; - const favoriteHobbies = ['skiing', 'skydiving', 'biking']; - - // We don't need to airdrop if we're using the local cluster - // because the local cluster gives us 85 billion dollars worth of SOL - before(async () => { - const balance = await provider.connection.getBalance(user.publicKey); - const balanceInSOL = balance / web3.LAMPORTS_PER_SOL; - const formattedBalance = new Intl.NumberFormat().format(balanceInSOL); - console.log(`Balance: ${formattedBalance} SOL`); - }); - - it('Writes our favorites to the blockchain', async () => { - await program.methods - // set_favourites in Rust becomes setFavorites in TypeScript - .setFavorites(favoriteNumber, favoriteColor, favoriteHobbies) - // Sign the transaction - .signers([user]) - // Send the transaction to the cluster or RPC - .rpc(); - - // Find the PDA for the user's favorites - const favoritesPdaAndBump = web3.PublicKey.findProgramAddressSync([Buffer.from('favorites'), user.publicKey.toBuffer()], program.programId); - const favoritesPda = favoritesPdaAndBump[0]; - const dataFromPda = await program.account.favorites.fetch(favoritesPda); - // And make sure it matches! - assert.equal(dataFromPda.color, favoriteColor); - // A little extra work to make sure the BNs are equal - assert.equal(dataFromPda.number.toString(), favoriteNumber.toString()); - // And check the hobbies too - assert.deepEqual(dataFromPda.hobbies, favoriteHobbies); - }); - - it('Updates the favorites', async () => { - const newFavoriteHobbies = ['skiing', 'skydiving', 'biking', 'swimming']; - try { - const signature = await program.methods.setFavorites(favoriteNumber, favoriteColor, newFavoriteHobbies).signers([user]).rpc(); - - console.log(`Transaction signature: ${signature}`); - } catch (error) { - console.error((error as Error).message); - const customErrorMessage = getCustomErrorMessage(systemProgramErrors, error); - throw new Error(customErrorMessage); - } - }); - - it('Rejects transactions from unauthorized signers', async () => { - try { - await program.methods - // set_favourites in Rust becomes setFavorites in TypeScript - .setFavorites(favoriteNumber, favoriteColor, favoriteHobbies) - // Sign the transaction - .signers([someRandomGuy]) - // Send the transaction to the cluster or RPC - .rpc(); - } catch (error) { - const errorMessage = (error as Error).message; - assert.isTrue(errorMessage.includes('unknown signer')); - } - }); -}); diff --git a/basics/favorites/anchor/tests/litesvm.test.ts b/basics/favorites/anchor/tests/litesvm.test.ts new file mode 100644 index 000000000..89fffe52e --- /dev/null +++ b/basics/favorites/anchor/tests/litesvm.test.ts @@ -0,0 +1,143 @@ +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/favorites.json" with { type: "json" }; + +describe("LiteSVM: Favorites", () => { + const svm = new LiteSVM(); + const programId = new PublicKey(IDL.address); + const coder = new anchor.BorshCoder(IDL as anchor.Idl); //For serialization and deserialization + const payer = Keypair.generate(); + svm.airdrop(payer.publicKey, BigInt(1000000000)); + + const programPath = new URL("../target/deploy/favorites.so", import.meta.url) + .pathname; + svm.addProgramFromFile(programId, programPath); + + const [favPdaAccount] = PublicKey.findProgramAddressSync( + [Buffer.from("favorites"), payer.publicKey.toBuffer()], + programId, + ); + /** + * Here's what we want to write to the blockchain + */ + const favoriteNumber = new anchor.BN(23); + const favoriteColor = "purple"; + const favoriteHobbies = ["skiing", "skydiving", "biking"]; + + it("Writes our favorites to the blockchain", () => { + const ixArgs = { + number: favoriteNumber, + color: favoriteColor, + hobbies: favoriteHobbies, + }; + + const data = coder.instruction.encode("set_favorites", ixArgs); + const ix = new TransactionInstruction({ + keys: [ + { pubkey: payer.publicKey, isSigner: true, isWritable: true }, + { pubkey: favPdaAccount, isSigner: false, 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); + svm.sendTransaction(tx); + + /** + * Fetch the account and check its favorites + */ + const favAccountInfo = svm.getAccount(favPdaAccount); + const favAccount = coder.accounts.decode( + "Favorites", + Buffer.from(favAccountInfo.data), + ); + + assert.equal(favAccount.number.toNumber(), favoriteNumber.toNumber()); + assert.equal(favAccount.color, favoriteColor); + assert.deepStrictEqual(favAccount.hobbies, favoriteHobbies); + }); + + it("Updates the favorites", () => { + const newFavoriteHobbies = ["coding", "reading", "biking", "swimming"]; + const ixArgs = { + number: favoriteNumber, + color: favoriteColor, + hobbies: newFavoriteHobbies, + }; + + const data = coder.instruction.encode("set_favorites", ixArgs); + const ix = new TransactionInstruction({ + keys: [ + { pubkey: payer.publicKey, isSigner: true, isWritable: true }, + { pubkey: favPdaAccount, isSigner: false, 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); + svm.sendTransaction(tx); + + /** + * Fetch the account and check its favorites + */ + const favAccountInfo = svm.getAccount(favPdaAccount); + const favAccount = coder.accounts.decode( + "Favorites", + Buffer.from(favAccountInfo.data), + ); + + assert.equal(favAccount.number.toNumber(), favoriteNumber.toNumber()); + assert.equal(favAccount.color, favoriteColor); + assert.deepStrictEqual(favAccount.hobbies, newFavoriteHobbies); + }); + + it("Rejects transactions from unauthorized signers", () => { + const newFavoriteHobbies = ["coding", "reading", "biking"]; + const someRandomGuy = Keypair.generate(); + + const ixArgs = { + number: favoriteNumber, + color: favoriteColor, + hobbies: newFavoriteHobbies, + }; + + const data = coder.instruction.encode("set_favorites", ixArgs); + const ix = new TransactionInstruction({ + keys: [ + { pubkey: payer.publicKey, isSigner: true, isWritable: true }, + { pubkey: favPdaAccount, isSigner: false, 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(); + + assert.Throw(() => { + tx.sign(someRandomGuy); + svm.sendTransaction(tx); + }, "unknown signer"); + }); +}); diff --git a/basics/favorites/anchor/tests/system-errors.ts b/basics/favorites/anchor/tests/system-errors.ts deleted file mode 100644 index 845ce2f30..000000000 --- a/basics/favorites/anchor/tests/system-errors.ts +++ /dev/null @@ -1,20 +0,0 @@ -// From https://github.com/solana-labs/solana/blob/a94920a4eadf1008fc292e47e041c1b3b0d949df/sdk/program/src/system_instruction.rs -export const systemProgramErrors = [ - 'an account with the same address already exists', - - 'account does not have enough SOL to perform the operation', - - 'cannot assign account to this program id', - - 'cannot allocate account data of this length', - - 'length of requested seed is too long', - - 'provided address does not match addressed derived from seed', - - 'advancing stored nonce requires a populated RecentBlockhashes sysvar', - - 'stored nonce is still in recent_blockhashes', - - 'specified nonce does not match stored nonce', -]; diff --git a/basics/favorites/anchor/tests/test.ts b/basics/favorites/anchor/tests/test.ts new file mode 100644 index 000000000..6a2c1b95f --- /dev/null +++ b/basics/favorites/anchor/tests/test.ts @@ -0,0 +1,87 @@ +import type { Program } from "@coral-xyz/anchor"; +import * as anchor from "@coral-xyz/anchor"; +import { BN } from "bn.js"; +import { assert } from "chai"; +import type { Favorites } from "../target/types/favorites.ts"; + +describe("Anchor: Favorites", () => { + // Use the cluster and the keypair from Anchor.toml + const provider = anchor.AnchorProvider.env(); + anchor.setProvider(provider); + const web3 = anchor.web3; + // See https://github.com/coral-xyz/anchor/issues/3122 + const user = (provider.wallet as anchor.Wallet).payer; + const someRandomGuy = anchor.web3.Keypair.generate(); + const program = anchor.workspace.Favorites as Program; + + // Here's what we want to write to the blockchain + const favoriteNumber = new BN(23); + const favoriteColor = "purple"; + const favoriteHobbies = ["skiing", "skydiving", "biking"]; + + // We don't need to airdrop if we're using the local cluster + // because the local cluster gives us 85 billion dollars worth of SOL + before(async () => { + const balance = await provider.connection.getBalance(user.publicKey); + const balanceInSOL = balance / web3.LAMPORTS_PER_SOL; + const formattedBalance = new Intl.NumberFormat().format(balanceInSOL); + console.log(`Balance: ${formattedBalance} SOL`); + }); + + it("Writes our favorites to the blockchain", async () => { + await program.methods + // set_favourites in Rust becomes setFavorites in TypeScript + .setFavorites(favoriteNumber, favoriteColor, favoriteHobbies) + // Sign the transaction + .signers([user]) + // Send the transaction to the cluster or RPC + .rpc(); + + // Find the PDA for the user's favorites + const favoritesPdaAndBump = web3.PublicKey.findProgramAddressSync( + [Buffer.from("favorites"), user.publicKey.toBuffer()], + program.programId, + ); + const favoritesPda = favoritesPdaAndBump[0]; + const dataFromPda = await program.account.favorites.fetch(favoritesPda); + // And make sure it matches! + assert.equal(dataFromPda.color, favoriteColor); + // A little extra work to make sure the BNs are equal + assert.equal(dataFromPda.number.toString(), favoriteNumber.toString()); + // And check the hobbies too + assert.deepEqual(dataFromPda.hobbies, favoriteHobbies); + }); + + it("Updates the favorites", async () => { + const newFavoriteHobbies = ["skiing", "skydiving", "biking", "swimming"]; + + await program.methods + .setFavorites(favoriteNumber, favoriteColor, newFavoriteHobbies) + .signers([user]) + .rpc(); + + // Find the PDA for the user's favorites + const favoritesPdaAndBump = web3.PublicKey.findProgramAddressSync( + [Buffer.from("favorites"), user.publicKey.toBuffer()], + program.programId, + ); + const favoritesPda = favoritesPdaAndBump[0]; + const dataFromPda = await program.account.favorites.fetch(favoritesPda); + + assert.equal(dataFromPda.color, favoriteColor); + assert.equal(dataFromPda.number.toString(), favoriteNumber.toString()); + assert.deepEqual(dataFromPda.hobbies, newFavoriteHobbies); + }); + + it("Rejects transactions from unauthorized signers", async () => { + try { + await program.methods + .setFavorites(favoriteNumber, favoriteColor, favoriteHobbies) + .signers([someRandomGuy]) + .rpc(); + assert.fail("Expected unauthorized signer error"); + } catch (err) { + assert.include((err as Error).message, "unknown signer"); + } + }); +}); diff --git a/basics/favorites/anchor/tsconfig.json b/basics/favorites/anchor/tsconfig.json index cd5d2e3d0..fdf5c04de 100644 --- a/basics/favorites/anchor/tsconfig.json +++ b/basics/favorites/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 + } }