Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Upgrade the codebase to work with testnet XDR #135

Merged
merged 3 commits into from
Sep 12, 2023
Merged
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 @@ -139,7 +139,7 @@
"axios": "^1.4.0",
"bignumber.js": "^9.1.1",
"buffer": "^6.0.3",
"stellar-base": "10.0.0-soroban.8",
"stellar-base": "v10.0.0-beta.0",
"urijs": "^1.19.1"
}
}
3 changes: 1 addition & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ export class Server {

let contractKey: string = xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: scAddress,
key,
contract: scAddress,
durability: xdrDurability,
bodyType: xdr.ContractEntryBodyType.dataEntry(), // expirationExtension is internal
}),
).toXDR("base64");

Expand Down
14 changes: 5 additions & 9 deletions test/unit/server/get_contract_data_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const MockAdapter = require('axios-mock-adapter');
const xdr = SorobanClient.xdr;
const Address = SorobanClient.Address;
const { xdr } = SorobanClient;

describe('Server#getContractData', function () {
beforeEach(function () {
Expand Down Expand Up @@ -34,12 +32,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()
durability: xdr.ContractDataDurability.persistent()
})
).toXDR('base64')
]
Expand Down Expand Up @@ -77,12 +74,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()
durability: xdr.ContractDataDurability.temporary()
})
).toXDR('base64')
]
Expand Down
21 changes: 12 additions & 9 deletions test/unit/server/simulate_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ describe('Server#simulateTransaction', function () {
address: address,
nonce: new xdr.Int64(1234),
signatureExpirationLedger: 1,
signatureArgs: []
signature: xdr.ScVal.scvVoid()
})
),
// Basic fake invocation
rootInvocation: new xdr.SorobanAuthorizedInvocation({
function:
xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn(
new xdr.SorobanAuthorizedContractFunction({
new xdr.InvokeContractArgs({
contractAddress: address,
functionName: 'test',
args: []
Expand Down Expand Up @@ -80,18 +80,21 @@ describe('Server#simulateTransaction', function () {
'1'
);
function emptyContractTransaction() {
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: address,
functionName: 'fn',
args: []
})
),
auth: []
})
)
.setTimeout(SorobanClient.TimeoutInfinite)
.build();
}

Expand Down
21 changes: 12 additions & 9 deletions test/unit/transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,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 Down Expand Up @@ -60,18 +60,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: xdr.HostFunction.hostFunctionTypeInvokeContract(
new xdr.InvokeContractArgs({
contractAddress: scAddress,
functionName: 'hello',
args: [xdr.ScVal.scvString('hello')]
})
),
auth: auth ?? []
})
)
.setTimeout(SorobanClient.TimeoutInfinite)
.build();
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6620,10 +6620,10 @@ statuses@~1.5.0:
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==

stellar-base@10.0.0-soroban.8:
version "10.0.0-soroban.8"
resolved "https://registry.yarnpkg.com/stellar-base/-/stellar-base-10.0.0-soroban.8.tgz#8c5671f9d5a183aeb3077746db56e65b0b5c05da"
integrity sha512-mtj+4EcCnp4ZyH2FzRl62/DAstTXOddHVRZdzFQ94WgyQz2yVNzt+ANDS1D/7ku4d2mIzoJIj9l0/H0A5nRgXQ==
stellar-base@v10.0.0-beta.0:
version "10.0.0-beta.0"
resolved "https://registry.yarnpkg.com/stellar-base/-/stellar-base-10.0.0-beta.0.tgz#c8663996ef6fcfd569977f4534688c94b3939a39"
integrity sha512-YYUUCERjlok4yzCC3XXuvfvMw1POHCXE6JELjYgFGMaMx8IS8pAN9mdW/H7n1Sdo1c57jaDfPwZYFrgzRtU4kQ==
dependencies:
base32.js "^0.1.0"
bignumber.js "^9.1.2"
Expand Down