Skip to content

Commit

Permalink
Add all changes matching stellar/js-soroban-client#167
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic authored and willemneal committed Dec 6, 2023
1 parent ae9f608 commit e91e048
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 203 deletions.
42 changes: 21 additions & 21 deletions test/unit/server/soroban/get_account_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Account, Keypair, StrKey, hash, xdr } = StellarSdk;
const { Server, AxiosClient } = StellarSdk.SorobanRpc;

describe("Server#getAccount", function () {
describe('Server#getAccount', function () {
beforeEach(function () {
this.server = new Server(serverUrl);
this.axiosMock = sinon.mock(AxiosClient);
Expand All @@ -12,17 +12,17 @@ describe("Server#getAccount", function () {
this.axiosMock.restore();
});

const address = "GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI";
const address = 'GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI';
const accountId = Keypair.fromPublicKey(address).xdrPublicKey();
const key = xdr.LedgerKey.account(new xdr.LedgerKeyAccount({ accountId }));
const accountEntry =
"AAAAAAAAAABzdv3ojkzWHMD7KUoXhrPx0GH18vHKV0ZfqpMiEblG1g3gtpoE608YAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAQAAAAAY9D8iA";

it("requests the correct method", function (done) {
it('requests the correct method', function (done) {
this.axiosMock
.expects("post")
.expects('post')
.withArgs(serverUrl, {
jsonrpc: "2.0",
jsonrpc: '2.0',
id: 1,
method: "getLedgerEntries",
params: [[key.toXDR("base64")]],
Expand All @@ -34,16 +34,16 @@ describe("Server#getAccount", function () {
latestLedger: 0,
entries: [
{
key: key.toXDR("base64"),
xdr: accountEntry,
},
],
},
},
}),
key: key.toXDR('base64'),
xdr: accountEntry
}
]
}
}
})
);

const expected = new Account(address, "1");
const expected = new Account(address, '1');
this.server
.getAccount(address)
.then(function (response) {
Expand All @@ -57,9 +57,9 @@ describe("Server#getAccount", function () {
const address = "GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI";

this.axiosMock
.expects("post")
.expects('post')
.withArgs(serverUrl, {
jsonrpc: "2.0",
jsonrpc: '2.0',
id: 1,
method: "getLedgerEntries",
params: [[key.toXDR("base64")]],
Expand All @@ -69,22 +69,22 @@ describe("Server#getAccount", function () {
data: {
result: {
latestLedger: 0,
entries: null,
},
},
}),
entries: null
}
}
})
);

this.server
.getAccount(address)
.then(function (_) {
done(new Error("Expected error to be thrown"));
done(new Error('Expected error to be thrown'));
})
.catch(function (err) {
done(
err.message === `Account not found: ${address}`
? null
: new Error(`Received unexpected error: ${err.message}`),
: new Error(`Received unexpected error: ${err.message}`)
);
});
});
Expand Down
32 changes: 16 additions & 16 deletions test/unit/server/soroban/get_contract_data_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Address, xdr, nativeToScVal, hash } = StellarSdk;
const { Server, AxiosClient, Durability } = StellarSdk.SorobanRpc;

describe("Server#getContractData", function () {
describe('Server#getContractData', function () {
beforeEach(function () {
this.server = new Server(serverUrl);
this.axiosMock = sinon.mock(AxiosClient);
Expand All @@ -12,26 +12,26 @@ describe("Server#getContractData", function () {
this.axiosMock.restore();
});

const address = "CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5";
const key = nativeToScVal(["Admin"]);
const address = 'CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5';
const key = nativeToScVal(['Admin']);

const ledgerEntry = xdr.LedgerEntryData.contractData(
new xdr.ContractDataEntry({
ext: new xdr.ExtensionPoint(0),
contract: new Address(address).toScAddress(),
durability: xdr.ContractDataDurability.persistent(),
key,
val: key, // lazy
}),
val: key // lazy
})
);

// the key is a subset of the val
const ledgerKey = xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: ledgerEntry.contractData().contract(),
durability: ledgerEntry.contractData().durability(),
key: ledgerEntry.contractData().key(),
}),
key: ledgerEntry.contractData().key()
})
);

const ledgerTtlEntry = xdr.LedgerEntryData.ttl(
Expand All @@ -41,7 +41,7 @@ describe("Server#getContractData", function () {
}),
);

it("contract data key found", function (done) {
it('contract data key found', function (done) {
let result = {
lastModifiedLedgerSeq: 1,
key: ledgerKey,
Expand All @@ -50,9 +50,9 @@ describe("Server#getContractData", function () {
};

this.axiosMock
.expects("post")
.expects('post')
.withArgs(serverUrl, {
jsonrpc: "2.0",
jsonrpc: '2.0',
id: 1,
method: "getLedgerEntries",
params: [[ledgerKey.toXDR("base64")]],
Expand Down Expand Up @@ -94,9 +94,9 @@ describe("Server#getContractData", function () {
.durability(xdr.ContractDataDurability.temporary());

this.axiosMock
.expects("post")
.expects('post')
.withArgs(serverUrl, {
jsonrpc: "2.0",
jsonrpc: '2.0',
id: 1,
method: "getLedgerEntries",
params: [[ledgerKeyDupe.toXDR("base64")]],
Expand All @@ -106,19 +106,19 @@ describe("Server#getContractData", function () {
this.server
.getContractData(address, key, Durability.Temporary)
.then(function (_response) {
done(new Error("Expected error"));
done(new Error('Expected error'));
})
.catch(function (err) {
done(
err.code == 404
? null
: new Error("Expected error code 404, got: " + err.code),
: new Error('Expected error code 404, got: ' + err.code)
);
});
});

it("fails on hex address (was deprecated now unsupported)", function (done) {
let hexAddress = "0".repeat(63) + "1";
it('fails on hex address (was deprecated now unsupported)', function (done) {
let hexAddress = '0'.repeat(63) + '1';
this.server
.getContractData(hexAddress, key, Durability.Persistent)
.then((reply) => done(new Error(`should fail, got: ${reply}`)))
Expand Down
50 changes: 25 additions & 25 deletions test/unit/server/soroban/get_ledger_entries_test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const { xdr, nativeToScVal, Durability, hash } = StellarSdk;
const { Server, AxiosClient } = StellarSdk.SorobanRpc;

describe("Server#getLedgerEntries", function () {
const address = "CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5";
const key = nativeToScVal(["test"]);
describe('Server#getLedgerEntries', function () {
const address = 'CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5';
const key = nativeToScVal(['test']);
const ledgerEntry = xdr.LedgerEntryData.contractData(
new xdr.ContractDataEntry({
ext: new xdr.ExtensionPoint(0),
contract: new StellarSdk.Address(address).toScAddress(),
durability: xdr.ContractDataDurability.persistent(),
key,
val: key,
}),
val: key
})
);
const ledgerKey = xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: ledgerEntry.contractData().contract(),
durability: ledgerEntry.contractData().durability(),
key: ledgerEntry.contractData().key(),
}),
key: ledgerEntry.contractData().key()
})
);
const ledgerTtlEntry = new xdr.TtlEntry({
keyHash: hash(ledgerKey.toXDR()),
Expand All @@ -39,22 +39,22 @@ describe("Server#getLedgerEntries", function () {

function mockRPC(axiosMock, requests, entries) {
axiosMock
.expects("post")
.expects('post')
.withArgs(serverUrl, {
jsonrpc: "2.0",
jsonrpc: '2.0',
id: 1,
method: "getLedgerEntries",
params: [requests],
method: 'getLedgerEntries',
params: [requests]
})
.returns(
Promise.resolve({
data: {
result: {
latestLedger: 420,
entries,
},
},
}),
entries
}
}
})
);
}

Expand All @@ -67,9 +67,9 @@ describe("Server#getLedgerEntries", function () {
liveUntilLedgerSeq: ledgerTtlEntry.liveUntilLedgerSeq(),
lastModifiedLedgerSeq: 2,
key: ledgerKeyXDR,
xdr: ledgerEntryXDR,
},
],
xdr: ledgerEntryXDR
}
]
);

this.server
Expand All @@ -94,9 +94,9 @@ describe("Server#getLedgerEntries", function () {
{
lastModifiedLedgerSeq: 2,
key: ledgerKeyXDR,
xdr: ledgerEntryXDR,
},
],
xdr: ledgerEntryXDR
}
]
);

this.server
Expand All @@ -120,12 +120,12 @@ describe("Server#getLedgerEntries", function () {
[ledgerKeyXDR],
[
{
lastModifiedLedgerSeq: 2,
lastModifiedLedgerSeq: 2
},
{
lastModifiedLedgerSeq: 1,
},
],
lastModifiedLedgerSeq: 1
}
]
);

this.server
Expand Down
Loading

0 comments on commit e91e048

Please sign in to comment.