Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft] Update library to match upcoming testnet RPC and XDR updates #121

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"eventsource": "^2.0.2",
"lodash": "^4.17.21",
"randombytes": "^2.1.0",
"stellar-base": "10.0.0-soroban.6",
"stellar-base": "git+https://github.com/stellar/js-stellar-base#c909f1c",
"toml": "^3.0.0",
"urijs": "^1.19.1"
}
Expand Down
10 changes: 6 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ export class Server {
let contractKey: string = xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: scAddress,
key,
durability: xdrDurability,
bodyType: xdr.ContractEntryBodyType.dataEntry() // expirationExtension is internal
key,
})
).toXDR("base64");

Expand All @@ -221,13 +220,16 @@ export class Server {
"getLedgerEntries",
[contractKey],
).then(response => {
const ledgerEntries = response.entries ?? [];
const ledgerEntries = response.entries ?? [];
if (ledgerEntries.length !== 1) {
return Promise.reject({
code: 404,
message: `Contract data not found. Contract: ${Address.fromScAddress(scAddress).toString()}, Key: ${key.toXDR("base64")}, Durability: ${durability}`,
message: `Contract data not found. Contract: ${
Address.fromScAddress(scAddress).toString()
}, Key: ${key.toXDR("base64")}, Durability: ${durability}`,
});
}

return ledgerEntries[0];
});
}
Expand Down
6 changes: 2 additions & 4 deletions test/unit/server/get_contract_data_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ describe("Server#getContractData", function () {
[
xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
key,
contract: new SorobanClient.Contract(address)
.address()
.toScAddress(),
key,
durability: xdr.ContractDataDurability.persistent(),
bodyType: xdr.ContractEntryBodyType.dataEntry(),
})
).toXDR("base64"),
],
Expand Down Expand Up @@ -77,12 +76,11 @@ describe("Server#getContractData", function () {
[
xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
key,
contract: new SorobanClient.Contract(address)
.address()
.toScAddress(),
key,
durability: xdr.ContractDataDurability.temporary(),
bodyType: xdr.ContractEntryBodyType.dataEntry(),
})
).toXDR("base64"),
],
Expand Down
12 changes: 8 additions & 4 deletions test/unit/server/simulate_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("Server#simulateTransaction", function () {
instructions: 0,
readBytes: 0,
writeBytes: 0,
extendedMetaDataSizeBytes: 0,
contractEventsSizeBytes: 0,
}),
refundableFee: SorobanClient.xdr.Int64.fromString("0"),
ext: new SorobanClient.xdr.ExtensionPoint(0),
Expand All @@ -36,14 +36,14 @@ describe("Server#simulateTransaction", function () {
address: address,
nonce: new SorobanClient.xdr.Int64(1234),
signatureExpirationLedger: 1,
signatureArgs: [],
signature: SorobanClient.nativeToScVal(null),
})
),
// Basic fake invocation
rootInvocation: new SorobanClient.xdr.SorobanAuthorizedInvocation({
function:
SorobanClient.xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn(
new SorobanClient.xdr.SorobanAuthorizedContractFunction({
new SorobanClient.xdr.InvokeContractArgs({
contractAddress: address,
functionName: "test",
args: [],
Expand Down Expand Up @@ -78,7 +78,11 @@ describe("Server#simulateTransaction", function () {
.addOperation(
SorobanClient.Operation.invokeHostFunction({
func: new SorobanClient.xdr.HostFunction.hostFunctionTypeInvokeContract(
[]
new SorobanClient.xdr.InvokeContractArgs({
contractAddress: address,
functionName: "",
args: [],
})
),
auth: [],
})
Expand Down
38 changes: 15 additions & 23 deletions test/unit/transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ describe("assembleTransaction", () => {
address: scAddress,
nonce: new xdr.Int64(0),
signatureExpirationLedger: 1,
signatureArgs: [],
signature: xdr.ScVal.scvVoid(),
})
),
// And a basic invocation
rootInvocation: new xdr.SorobanAuthorizedInvocation({
function:
xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn(
new xdr.SorobanAuthorizedContractFunction({
new xdr.InvokeContractArgs({
contractAddress: scAddress,
functionName: "fn",
args: [],
Expand All @@ -33,20 +33,9 @@ describe("assembleTransaction", () => {
}),
});

const sorobanTransactionData = new xdr.SorobanTransactionData({
resources: new xdr.SorobanResources({
footprint: new xdr.LedgerFootprint({
readOnly: [],
readWrite: [],
}),
instructions: 0,
readBytes: 5,
writeBytes: 0,
extendedMetaDataSizeBytes: 0,
}),
refundableFee: xdr.Int64.fromString("0"),
ext: new xdr.ExtensionPoint(0),
});
const sorobanTransactionData = new SorobanClient.SorobanDataBuilder()
.setResources(0, 5, 0)
.build();

const simulationResponse = {
transactionData: sorobanTransactionData.toXDR("base64"),
Expand All @@ -72,18 +61,21 @@ describe("assembleTransaction", () => {
);

function singleContractFnTransaction(auth) {
return new SorobanClient.TransactionBuilder(source, {
fee: 100,
networkPassphrase: "Test",
v1: true,
})
return new SorobanClient.TransactionBuilder(source, { fee: 100 })
.setNetworkPassphrase("Test")
.setTimeout(SorobanClient.TimeoutInfinite)
.addOperation(
SorobanClient.Operation.invokeHostFunction({
func: new xdr.HostFunction.hostFunctionTypeInvokeContract([]),
func: new xdr.HostFunction.hostFunctionTypeInvokeContract(
new xdr.InvokeContractArgs({
contractAddress: scAddress,
functionName: "empty",
args: [],
})
),
auth: auth ?? [],
})
)
.setTimeout(SorobanClient.TimeoutInfinite)
.build();
}

Expand Down
Loading