Skip to content

Commit

Permalink
Upgrade stellar-base and adapt to its breaking changes (#158)
Browse files Browse the repository at this point in the history
* Raw upgrade to stellar-base
* Adapt to new async method
* Adapt tests to new method, add determinism
* Clean up unneeded code
  • Loading branch information
Shaptic committed Oct 9, 2023
1 parent ac06f2c commit f3c5c41
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 85 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
],
"sort": true,
"recursive": true,
"timeout": 60000
"timeout": 10000
},
"nyc": {
"instrument": false,
Expand Down Expand Up @@ -139,7 +139,7 @@
"axios": "^1.4.0",
"bignumber.js": "^9.1.1",
"buffer": "^6.0.3",
"stellar-base": "v10.0.0-beta.1",
"stellar-base": "v10.0.0-beta.3",
"urijs": "^1.19.1"
}
}
77 changes: 42 additions & 35 deletions test/unit/server/simulate_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const {
xdr
} = SorobanClient;

describe('Server#simulateTransaction', function () {
const randomSecret = Keypair.random().secret();

describe('Server#simulateTransaction', async function (done) {
let keypair = Keypair.random();
let contractId = 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM';
let contract = new SorobanClient.Contract(contractId);
let address = contract.address().toScAddress();

const simulationResponse = invokeSimulationResponse(address);
const simulationResponse = await invokeSimulationResponse(address);
const parsedSimulationResponse = {
id: simulationResponse.id,
events: simulationResponse.events,
Expand Down Expand Up @@ -104,36 +106,33 @@ describe('Server#simulateTransaction', function () {
expect(SorobanClient.SorobanRpc.isSimulationSuccess(parsed)).to.be.true;
});

it('works with no auth', function () {
const simResponse = invokeSimulationResponse(address);
delete simResponse.results[0].auth;

const parsedCopy = cloneSimulation(parsedSimulationResponse);
parsedCopy.result.auth = [];
const parsed = parseRawSimulation(simResponse);
it('works with no auth', async function () {
return invokeSimulationResponse(address).then((simResponse) => {
delete simResponse.results[0].auth;

// FIXME: This is a workaround for an xdrgen bug that does not allow you to
// build "perfectly-equal" xdr.ExtensionPoint instances (but they're still
// binary-equal, so the test passes).
parsedCopy.transactionData = parsedCopy.transactionData.build();
parsed.transactionData = parsed.transactionData.build();
const parsedCopy = cloneSimulation(parsedSimulationResponse);
parsedCopy.result.auth = [];
const parsed = parseRawSimulation(simResponse);

expect(parsed).to.be.deep.equal(parsedCopy);
expect(SorobanClient.SorobanRpc.isSimulationSuccess(parsed)).to.be.true;
expect(parsed).to.be.deep.equal(parsedCopy);
expect(SorobanClient.SorobanRpc.isSimulationSuccess(parsed)).to.be.true;
});
});

xit('works with restoration', function () {
const simResponse = invokeSimulationResponseWithRestoration(address);

const expected = cloneSimulation(parsedSimulationResponse);
expected.restorePreamble = {
minResourceFee: '51',
transactionData: new SorobanDataBuilder()
};

const parsed = parseRawSimulation(simResponse);
expect(parsed).to.be.deep.equal(expected);
expect(SorobanClient.SorobanRpc.isSimulationRestore(parsed)).to.be.true;
it('works with restoration', async function () {
return invokeSimulationResponseWithRestoration(address).then(
(simResponse) => {
const expected = cloneSimulation(parsedSimulationResponse);
expected.restorePreamble = {
minResourceFee: '51',
transactionData: new SorobanDataBuilder()
};

const parsed = parseRawSimulation(simResponse);
expect(SorobanClient.SorobanRpc.isSimulationRestore(parsed)).to.be.true;
expect(parsed).to.be.deep.equal(expected);
}
);
});

it('works with errors', function () {
Expand All @@ -154,6 +153,8 @@ describe('Server#simulateTransaction', function () {
});

xit('simulates fee bump transactions');

done();
});

function cloneSimulation(sim) {
Expand All @@ -174,7 +175,7 @@ function cloneSimulation(sim) {
};
}

function buildAuthEntry(address) {
async function buildAuthEntry(address) {
if (!address) {
throw new Error('where address?');
}
Expand All @@ -192,14 +193,20 @@ function buildAuthEntry(address) {
)
});

const kp = Keypair.random();
return authorizeInvocation(kp, Networks.FUTURENET, 1, root);
// do some voodoo to make this return a deterministic auth entry
const kp = Keypair.fromSecret(randomSecret);
let entry = authorizeInvocation(kp, 1, root);
entry.credentials().address().nonce(new xdr.Int64(0xdeadbeef));

return authorizeEntry(entry, kp, 1); // overwrites signature w/ above nonce
}

function invokeSimulationResponse(address) {
async function invokeSimulationResponse(address) {
return baseSimulationResponse([
{
auth: [buildAuthEntry(address)].map((entry) => entry.toXDR('base64')),
auth: [await buildAuthEntry(address)].map((entry) =>
entry.toXDR('base64')
),
xdr: xdr.ScVal.scvU32(0).toXDR('base64')
}
]);
Expand Down Expand Up @@ -229,9 +236,9 @@ function baseSimulationResponse(results) {
};
}

function invokeSimulationResponseWithRestoration(address) {
async function invokeSimulationResponseWithRestoration(address) {
return {
...invokeSimulationResponse(address),
...(await invokeSimulationResponse(address)),
restorePreamble: {
minResourceFee: '51',
transactionData: new SorobanDataBuilder().build().toXDR('base64')
Expand Down
103 changes: 55 additions & 48 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1471,9 +1471,11 @@
integrity sha512-NaHL0+0lLNhX6d9rs+NSt97WH/gIlRHmszXbQ/8/MV/eVcFNdeJ/GYhrFuUc8K7WuPhRhTSdMkCp8VMzhUq85w==

"@types/node@*", "@types/node@>=10.0.0", "@types/node@^20.6.0":
version "20.8.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.2.tgz#d76fb80d87d0d8abfe334fc6d292e83e5524efc4"
integrity sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==
version "20.8.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.4.tgz#0e9ebb2ff29d5c3302fc84477d066fa7c6b441aa"
integrity sha512-ZVPnqU58giiCjSxjVUESDtdPk4QR5WQhhINbc9UBrKLU68MX5BF6kbQzTrkwbolyr0X8ChBpXfavr5mZFKZQ5A==
dependencies:
undici-types "~5.25.1"

"@types/node@^14.14.35":
version "14.18.63"
Expand All @@ -1491,9 +1493,9 @@
integrity sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==

"@types/sinon@^10.0.16":
version "10.0.18"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-10.0.18.tgz#659d2059c2206162e111dfaa2d8e9e9837c68212"
integrity sha512-OpQC9ug8BcnNxue2WF5aTruMaDRFn6NyfaE4DmAKOlQMn54b7CnCvDFV3wj5fk/HbSSTYmOYs2bTb5ShANjyQg==
version "10.0.19"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-10.0.19.tgz#752b752bc40bb5af0bb1aec29bde49b139b91d35"
integrity sha512-MWZNGPSchIdDfb5FL+VFi4zHsHbNOTQEgjqFQk7HazXSXwUU9PAX3z9XBqb3AJGYr9YwrtCtaSMsT3brYsN/jQ==
dependencies:
"@types/sinonjs__fake-timers" "*"

Expand Down Expand Up @@ -1521,9 +1523,9 @@
integrity sha512-axdPBuLuEJt0c4yI5OZssC19K2Mq1uKdrfZBzuxLvaztgqUtFYZUNw7lETExPYJR9jdEoIg4mb7RQKRQzOkeGQ==

"@types/yargs@^17.0.8":
version "17.0.26"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.26.tgz#388e5002a8b284ad7b4599ba89920a6d74d8d79a"
integrity sha512-Y3vDy2X6zw/ZCumcwLpdhM5L7jmyGpmBCTYMHDLqT2IKVMYRRLdv6ZakA+wxhra6Z/3bwhNbNl9bDGXaFU+6rw==
version "17.0.28"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.28.tgz#d106e4301fbacde3d1796ab27374dd16588ec851"
integrity sha512-N3e3fkS86hNhtk6BEnc0rj3zcehaxx8QWhCROJkqpl5Zaoi7nAic3jH8q94jVD3zu5LGk+PUB6KAiDmimYOEQw==
dependencies:
"@types/yargs-parser" "*"

Expand Down Expand Up @@ -1554,14 +1556,14 @@
debug "^4.3.4"

"@typescript-eslint/parser@^6.7.0":
version "6.7.4"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.7.4.tgz#23d1dd4fe5d295c7fa2ab651f5406cd9ad0bd435"
integrity sha512-I5zVZFY+cw4IMZUeNCU7Sh2PO5O57F7Lr0uyhgCJmhN/BuTlnc55KxPonR4+EM3GBdfiCyGZye6DgMjtubQkmA==
dependencies:
"@typescript-eslint/scope-manager" "6.7.4"
"@typescript-eslint/types" "6.7.4"
"@typescript-eslint/typescript-estree" "6.7.4"
"@typescript-eslint/visitor-keys" "6.7.4"
version "6.7.5"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.7.5.tgz#8d7ca3d1fbd9d5a58cc4d30b2aa797a760137886"
integrity sha512-bIZVSGx2UME/lmhLcjdVc7ePBwn7CLqKarUBL4me1C5feOd663liTGjMBGVcGr+BhnSLeP4SgwdvNnnkbIdkCw==
dependencies:
"@typescript-eslint/scope-manager" "6.7.5"
"@typescript-eslint/types" "6.7.5"
"@typescript-eslint/typescript-estree" "6.7.5"
"@typescript-eslint/visitor-keys" "6.7.5"
debug "^4.3.4"

"@typescript-eslint/[email protected]":
Expand All @@ -1572,13 +1574,13 @@
"@typescript-eslint/types" "5.62.0"
"@typescript-eslint/visitor-keys" "5.62.0"

"@typescript-eslint/[email protected].4":
version "6.7.4"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.7.4.tgz#a484a17aa219e96044db40813429eb7214d7b386"
integrity sha512-SdGqSLUPTXAXi7c3Ob7peAGVnmMoGzZ361VswK2Mqf8UOYcODiYvs8rs5ILqEdfvX1lE7wEZbLyELCW+Yrql1A==
"@typescript-eslint/[email protected].5":
version "6.7.5"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.7.5.tgz#1cf33b991043886cd67f4f3600b8e122fc14e711"
integrity sha512-GAlk3eQIwWOJeb9F7MKQ6Jbah/vx1zETSDw8likab/eFcqkjSD7BI75SDAeC5N2L0MmConMoPvTsmkrg71+B1A==
dependencies:
"@typescript-eslint/types" "6.7.4"
"@typescript-eslint/visitor-keys" "6.7.4"
"@typescript-eslint/types" "6.7.5"
"@typescript-eslint/visitor-keys" "6.7.5"

"@typescript-eslint/[email protected]":
version "5.62.0"
Expand All @@ -1595,10 +1597,10 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f"
integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==

"@typescript-eslint/[email protected].4":
version "6.7.4"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.7.4.tgz#5d358484d2be986980c039de68e9f1eb62ea7897"
integrity sha512-o9XWK2FLW6eSS/0r/tgjAGsYasLAnOWg7hvZ/dGYSSNjCh+49k5ocPN8OmG5aZcSJ8pclSOyVKP2x03Sj+RrCA==
"@typescript-eslint/[email protected].5":
version "6.7.5"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.7.5.tgz#4571320fb9cf669de9a95d9849f922c3af809790"
integrity sha512-WboQBlOXtdj1tDFPyIthpKrUb+kZf2VroLZhxKa/VlwLlLyqv/PwUNgL30BlTVZV1Wu4Asu2mMYPqarSO4L5ZQ==

"@typescript-eslint/[email protected]", "@typescript-eslint/typescript-estree@^5.55.0":
version "5.62.0"
Expand All @@ -1613,13 +1615,13 @@
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/[email protected].4":
version "6.7.4"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.4.tgz#f2baece09f7bb1df9296e32638b2e1130014ef1a"
integrity sha512-ty8b5qHKatlNYd9vmpHooQz3Vki3gG+3PchmtsA4TgrZBKWHNjWfkQid7K7xQogBqqc7/BhGazxMD5vr6Ha+iQ==
"@typescript-eslint/[email protected].5":
version "6.7.5"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.5.tgz#4578de1a26e9f24950f029a4f00d1bfe41f15a39"
integrity sha512-NhJiJ4KdtwBIxrKl0BqG1Ur+uw7FiOnOThcYx9DpOGJ/Abc9z2xNzLeirCG02Ig3vkvrc2qFLmYSSsaITbKjlg==
dependencies:
"@typescript-eslint/types" "6.7.4"
"@typescript-eslint/visitor-keys" "6.7.4"
"@typescript-eslint/types" "6.7.5"
"@typescript-eslint/visitor-keys" "6.7.5"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
Expand Down Expand Up @@ -1648,12 +1650,12 @@
"@typescript-eslint/types" "5.62.0"
eslint-visitor-keys "^3.3.0"

"@typescript-eslint/[email protected].4":
version "6.7.4"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.4.tgz#80dfecf820fc67574012375859085f91a4dff043"
integrity sha512-pOW37DUhlTZbvph50x5zZCkFn3xzwkGtNoJHzIM3svpiSkJzwOYr/kVBaXmf+RAQiUDs1AHEZVNPg6UJCJpwRA==
"@typescript-eslint/[email protected].5":
version "6.7.5"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.5.tgz#84c68d6ceb5b12d5246b918b84f2b79affd6c2f1"
integrity sha512-3MaWdDZtLlsexZzDSdQWsFQ9l9nL8B80Z4fImSpyllFC/KLqWQRdEcB+gGGO+N3Q2uL40EsG66wZLsohPxNXvg==
dependencies:
"@typescript-eslint/types" "6.7.4"
"@typescript-eslint/types" "6.7.5"
eslint-visitor-keys "^3.4.1"

"@webassemblyjs/[email protected]", "@webassemblyjs/ast@^1.11.5":
Expand Down Expand Up @@ -3148,9 +3150,9 @@ [email protected]:
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

electron-to-chromium@^1.4.535:
version "1.4.544"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.544.tgz#fcb156d83f0ee6e4c9d030c6fedb2a37594f3abf"
integrity sha512-54z7squS1FyFRSUqq/knOFSptjjogLZXbKcYk3B0qkE1KZzvqASwRZnY2KzZQJqIYLVD38XZeoiMRflYSwyO4w==
version "1.4.546"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.546.tgz#673ff64862859b1593cebfbacc5fb6aebef7c457"
integrity sha512-cz9bBM26ZqoEmGHkdHXU3LP7OofVyEzRoMqfALQ9Au9WlB4rogAHzqj/NkNvw2JJjy4xuxS1me+pP2lbCD5Mfw==

elliptic@^6.5.3:
version "6.5.4"
Expand Down Expand Up @@ -4969,9 +4971,9 @@ karma@^6.4.2:
yargs "^16.1.1"

keyv@^4.5.3:
version "4.5.3"
resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.3.tgz#00873d2b046df737963157bd04f294ca818c9c25"
integrity sha512-QCiSav9WaX1PgETJ+SpNnx2PRRapJ/oRSXM4VO5OGYGSjrxbKPVFVhB3l2OCbLCk329N8qyAtsJjSjvVBWzEug==
version "4.5.4"
resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.4.tgz#a879a99e29452f942439f2a405e3af8b31d4de93"
integrity sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==
dependencies:
json-buffer "3.0.1"

Expand Down Expand Up @@ -6641,10 +6643,10 @@ statuses@~1.5.0:
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==

[email protected].1:
version "10.0.0-beta.1"
resolved "https://registry.yarnpkg.com/stellar-base/-/stellar-base-10.0.0-beta.1.tgz#5b4209fbc44b8af82dd3ee8b7f6f4397126d8c3b"
integrity sha512-zXC5AsbUsLi57JruyeIMv23s3iUxq/P2ZFrSJ+FerLIZjSAjY8EDs4zwY4LCuu7swUu46Lm8GK6sqxUZCPekHw==
[email protected].3:
version "10.0.0-beta.3"
resolved "https://registry.yarnpkg.com/stellar-base/-/stellar-base-10.0.0-beta.3.tgz#c90e261945c58e2176b0a50b9a7b96003ecb0768"
integrity sha512-+B1fOdsDWJEnYSYkKSAVHVngzaqDtD8wdDMT/FC+11MrohP3uGY1OmrEeVn34jiBmUlpYZVudDnpDMSXD4RqDA==
dependencies:
base32.js "^0.1.0"
bignumber.js "^9.1.2"
Expand Down Expand Up @@ -7193,6 +7195,11 @@ underscore@~1.13.2:
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.13.6.tgz#04786a1f589dc6c09f761fc5f45b89e935136441"
integrity sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==

undici-types@~5.25.1:
version "5.25.3"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.25.3.tgz#e044115914c85f0bcbb229f346ab739f064998c3"
integrity sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==

unicode-canonical-property-names-ecmascript@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz#301acdc525631670d39f6146e0e77ff6bbdebddc"
Expand Down

0 comments on commit f3c5c41

Please sign in to comment.