diff --git a/.gitignore b/.gitignore index 07517d6..cebd7a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.DS_Store + target/ **/*.rs.bk wasm-pack.log diff --git a/soroflare-wrangler/src/routes/snapshot.rs b/soroflare-wrangler/src/routes/snapshot.rs index 022891c..a526b44 100644 --- a/soroflare-wrangler/src/routes/snapshot.rs +++ b/soroflare-wrangler/src/routes/snapshot.rs @@ -222,6 +222,33 @@ mod test { // NOTE: currently the source account is inferred within the vm wrapper itself and already has // a xlm balance of 10000 XLM strooops by default. + #[test] + fn gentest() { + let contract_a = stellar_strkey::Contract::from_string( + "CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V", + ).unwrap().0.into(); + let contract_b = stellar_strkey::Contract::from_string( + "CBRIAA73VOIKPZYM5G3LGPF3NGCFXLR3IW22MKEYJAB3QBOMTUTRCASK", + ).unwrap().0.into(); + + let snapshot = WithSnapshotInput { + adjustment_config: SimulationAdjustmentConfig::default_adjustment(), + network_config: None, + network: Some("Test SDF Network ; September 2015".into()), + ledger_sequence: 0, + source: [0; 32], + ledger_entries: vec![], + contract_id: contract_b, + fname: String::from("add_with"), + params: vec![ + ScVal::Address(ScAddress::Contract(contract_a)), + ScVal::U32(5), + ScVal::U32(15), + ], + }; + println!("{}", serde_json::json!(snapshot)); + } + #[test] fn transfer_ignore_fees() { let source_account = AccountId(PublicKey::PublicKeyTypeEd25519(Uint256( diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..9b1ee42 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,175 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..abf5033 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,15 @@ +# tests + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.0.26. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/tests/bun.lockb b/tests/bun.lockb new file mode 100755 index 0000000..d260fd9 Binary files /dev/null and b/tests/bun.lockb differ diff --git a/tests/default.json b/tests/default.json new file mode 100644 index 0000000..ef66c0c --- /dev/null +++ b/tests/default.json @@ -0,0 +1,108 @@ +{ + "adjustment_config": { + "instructions": { + "additive_factor": 50000, + "multiplicative_factor": 1.02 + }, + "read_bytes": { + "additive_factor": 0, + "multiplicative_factor": 1.0 + }, + "refundable_fee": { + "additive_factor": 0, + "multiplicative_factor": 1.15 + }, + "tx_size": { + "additive_factor": 500, + "multiplicative_factor": 1.1 + }, + "write_bytes": { + "additive_factor": 0, + "multiplicative_factor": 1.0 + } + }, + "contract_id": [ + 98, + 128, + 3, + 251, + 171, + 144, + 167, + 231, + 12, + 233, + 182, + 179, + 60, + 187, + 105, + 132, + 91, + 174, + 59, + 69, + 181, + 166, + 40, + 152, + 72, + 3, + 184, + 5, + 204, + 157, + 39, + 17 + ], + "fname": "add_with", + "ledger_entries": [], + "ledger_sequence": 0, + "network": "Test SDF Network ; September 2015", + "network_config": null, + "params": [ + { + "address": "CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V" + }, + { + "u32": 5 + }, + { + "u32": 15 + } + ], + "source": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] +} \ No newline at end of file diff --git a/tests/index.ts b/tests/index.ts new file mode 100644 index 0000000..1ecc2e3 --- /dev/null +++ b/tests/index.ts @@ -0,0 +1,129 @@ +import { xdr, Address, scValToNative } from "@stellar/stellar-sdk"; + +const path = "./snapshot.json"; +const file = Bun.file(path); +const snapshot = await file.json(); + +const json = { + "adjustment_config": { + "instructions": { + "additive_factor": 50000, + "multiplicative_factor": 1.02 + }, + "read_bytes": { + "additive_factor": 0, + "multiplicative_factor": 1.0 + }, + "refundable_fee": { + "additive_factor": 0, + "multiplicative_factor": 1.15 + }, + "tx_size": { + "additive_factor": 500, + "multiplicative_factor": 1.1 + }, + "write_bytes": { + "additive_factor": 0, + "multiplicative_factor": 1.0 + } + }, + "contract": [ + 98, + 128, + 3, + 251, + 171, + 144, + 167, + 231, + 12, + 233, + 182, + 179, + 60, + 187, + 105, + 132, + 91, + 174, + 59, + 69, + 181, + 166, + 40, + 152, + 72, + 3, + 184, + 5, + 204, + 157, + 39, + 17 + ], + "fname": "add_with", + "ledger_entries": snapshot.ledger.ledger_entries, + "ledger_sequence": 0, + "network": "Test SDF Network ; September 2015", + "network_config": null, + "args": [ + { + "address": "CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V" + }, + { + "u32": 5 + }, + { + "u32": 95 + } + ], + "source_account": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] +} + +fetch('http://localhost:8787/executesnapshot', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(json) +}) + .then(response => response.json()) + .then((data: any) => { + console.log(JSON.stringify(data, null, 2)); + // console.log( + // scValToNative(xdr.ScVal.fromXDR(data.opt.results.xdr, 'base64')) + // ); + }) \ No newline at end of file diff --git a/tests/package.json b/tests/package.json new file mode 100644 index 0000000..c5be0f0 --- /dev/null +++ b/tests/package.json @@ -0,0 +1,14 @@ +{ + "name": "tests", + "module": "index.ts", + "type": "module", + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "dependencies": { + "@stellar/stellar-sdk": "^11.2.2" + } +} \ No newline at end of file diff --git a/tests/snapshot.json b/tests/snapshot.json new file mode 100644 index 0000000..70bdf9a --- /dev/null +++ b/tests/snapshot.json @@ -0,0 +1,244 @@ +{ + "generators": { + "address": 2, + "nonce": 0 + }, + "auth": [ + [] + ], + "ledger": { + "protocol_version": 20, + "sequence_number": 0, + "timestamp": 0, + "network_id": "0000000000000000000000000000000000000000000000000000000000000000", + "base_reserve": 0, + "min_persistent_entry_ttl": 4096, + "min_temp_entry_ttl": 16, + "max_entry_ttl": 6312000, + "ledger_entries": [ + [ + { + "contract_data": { + "contract": "CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V", + "key": "ledger_key_contract_instance", + "durability": "persistent" + } + }, + [ + { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V", + "key": "ledger_key_contract_instance", + "durability": "persistent", + "val": { + "contract_instance": { + "executable": { + "wasm": "61f3ec45073b00a29bce98268932a9dcfa4f803efd2a425e0938d44047608b4d" + }, + "storage": null + } + } + } + }, + "ext": "v0" + }, + 4095 + ] + ], + [ + { + "contract_data": { + "contract": "CBRIAA73VOIKPZYM5G3LGPF3NGCFXLR3IW22MKEYJAB3QBOMTUTRCASK", + "key": "ledger_key_contract_instance", + "durability": "persistent" + } + }, + [ + { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CBRIAA73VOIKPZYM5G3LGPF3NGCFXLR3IW22MKEYJAB3QBOMTUTRCASK", + "key": "ledger_key_contract_instance", + "durability": "persistent", + "val": { + "contract_instance": { + "executable": { + "wasm": "ba45dcc500ee79e4e6dad8017a74b25341ff527529677d5c24948cbfb7676e94" + }, + "storage": null + } + } + } + }, + "ext": "v0" + }, + 4095 + ] + ], + [ + { + "contract_code": { + "hash": "61f3ec45073b00a29bce98268932a9dcfa4f803efd2a425e0938d44047608b4d" + } + }, + [ + { + "last_modified_ledger_seq": 0, + "data": { + "contract_code": { + "ext": "v0", + "hash": "61f3ec45073b00a29bce98268932a9dcfa4f803efd2a425e0938d44047608b4d", + "code": "0061736d01000000010a0260027e7e017e6000000305040001010105030100100619037f01418080c0000b7f00418080c0000b7f00418080c0000b072f05066d656d6f72790200036164640000015f00030a5f5f646174615f656e6403010b5f5f686561705f6261736503020a5d044901027f02400240200042ff01834204520d00200142ff01834204520d002000422088a722022001422088a76a22032002490d012003ad4220864204840f0b00000b108180808000000b0900108280808000000b040000000b02000b004b0e636f6e7472616374737065637630000000000000000000000003616464000000000200000000000000017800000000000004000000000000000179000000000000040000000100000004001e11636f6e7472616374656e766d6574617630000000000000001400000000006f0e636f6e74726163746d65746176300000000000000005727376657200000000000006312e37362e3000000000000000000008727373646b7665720000002f32302e332e32233164376639626438303330663639303730363334626662303733393433333938323463656233393900" + } + }, + "ext": "v0" + }, + 4095 + ] + ], + [ + { + "contract_code": { + "hash": "ba45dcc500ee79e4e6dad8017a74b25341ff527529677d5c24948cbfb7676e94" + } + }, + [ + { + "last_modified_ledger_seq": 0, + "data": { + "contract_code": { + "ext": "v0", + "hash": "ba45dcc500ee79e4e6dad8017a74b25341ff527529677d5c24948cbfb7676e94", + "code": "0061736d0100000001150460027e7e017e60037e7e7e017e60017f006000000213030162016a00000176016700000164015f00010305040102030305030100110619037f01418080c0000b7f00418380c0000b7f00419080c0000b073405066d656d6f72790200086164645f776974680003015f00060a5f5f646174615f656e6403010b5f5f686561705f6261736503020ae50304d00303017f017e037f23808080800041206b22032480808080000240200042ff018342cd00520d00200142ff01834204520d00200242ff01834204520d002001428080808070832104200242808080807083210242002101417d210502400240024003402005450d014101210602402005418380c080006a2d0000220741df00460d000240200741506a41ff0171410a490d000240200741bf7f6a41ff0171411a490d002007419f7f6a41ff017141194b0d05200741456a21060c020b2007414b6a21060c010b200741526a21060b20014206862006ad42ff0183842101200541016a21050c000b0b2001420886420e8421010c010b418080c08000ad42208642048442848080803010808080800021010b20032002420484370308200320044204843703004100210502400340024020054110470d00410021050240034020054110460d01200341106a20056a200320056a290300370300200541086a21050c000b0b20002001200341106aad422086420484428480808020108180808000108280808000220142ff01834204520d02200341206a2480808080002001428080808070834204840f0b200341106a20056a4202370300200541086a21050c000b0b200341106a108480808000000b00000b0900108580808000000b040000000b02000b0b0c0100418080c0000b0361646400630e636f6e74726163747370656376300000000000000000000000086164645f77697468000000030000000000000008636f6e74726163740000001300000000000000017800000000000004000000000000000179000000000000040000000100000004001e11636f6e7472616374656e766d6574617630000000000000001400000000006f0e636f6e74726163746d65746176300000000000000005727376657200000000000006312e37362e3000000000000000000008727373646b7665720000002f32302e332e32233164376639626438303330663639303730363334626662303733393433333938323463656233393900" + } + }, + "ext": "v0" + }, + 4095 + ] + ] + ] + }, + "events": [ + { + "event": { + "ext": "v0", + "contract_id": null, + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_call" + }, + { + "bytes": "628003fbab90a7e70ce9b6b33cbb69845bae3b45b5a628984803b805cc9d2711" + }, + { + "symbol": "add_with" + } + ], + "data": { + "vec": [ + { + "address": "CBKMUZNFQIAL775XBB2W2GP5CNHBM5YGH6C3XB7AY6SUVO2IBU3VYK2V" + }, + { + "u32": 5 + }, + { + "u32": 7 + } + ] + } + } + } + }, + "failed_call": false + }, + { + "event": { + "ext": "v0", + "contract_id": "628003fbab90a7e70ce9b6b33cbb69845bae3b45b5a628984803b805cc9d2711", + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_call" + }, + { + "bytes": "54ca65a58200bfffb708756d19fd134e1677063f85bb87e0c7a54abb480d375c" + }, + { + "symbol": "add" + } + ], + "data": { + "vec": [ + { + "u32": 5 + }, + { + "u32": 7 + } + ] + } + } + } + }, + "failed_call": false + }, + { + "event": { + "ext": "v0", + "contract_id": "54ca65a58200bfffb708756d19fd134e1677063f85bb87e0c7a54abb480d375c", + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_return" + }, + { + "symbol": "add" + } + ], + "data": { + "u32": 12 + } + } + } + }, + "failed_call": false + }, + { + "event": { + "ext": "v0", + "contract_id": "628003fbab90a7e70ce9b6b33cbb69845bae3b45b5a628984803b805cc9d2711", + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_return" + }, + { + "symbol": "add_with" + } + ], + "data": { + "u32": 12 + } + } + } + }, + "failed_call": false + } + ] +} \ No newline at end of file diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 0000000..dcd8fc5 --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + /* Linting */ + "skipLibCheck": true, + "strict": true, + "noFallthroughCasesInSwitch": true, + "forceConsistentCasingInFileNames": true + } +}