Skip to content

Commit

Permalink
Formatting fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Dec 1, 2023
1 parent 717f1fd commit 5d945c6
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 238 deletions.
56 changes: 28 additions & 28 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,20 +12,20 @@ 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';
"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')]]
method: "getLedgerEntries",
params: [[key.toXDR("base64")]],
})
.returns(
Promise.resolve({
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 @@ -53,38 +53,38 @@ describe('Server#getAccount', function () {
.catch(done);
});

it('throws a useful error when the account is not found', function (done) {
const address = 'GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI';
it("throws a useful error when the account is not found", function (done) {
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')]]
method: "getLedgerEntries",
params: [[key.toXDR("base64")]],
})
.returns(
Promise.resolve({
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
66 changes: 33 additions & 33 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,50 +12,50 @@ 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(
new xdr.TtlEntry({
keyHash: hash(ledgerKey.toXDR()),
liveUntilLedgerSeq: 1000
})
liveUntilLedgerSeq: 1000,
}),
);

it('contract data key found', function (done) {
it("contract data key found", function (done) {
let result = {
lastModifiedLedgerSeq: 1,
key: ledgerKey,
val: ledgerEntry,
liveUntilLedgerSeq: 1000
liveUntilLedgerSeq: 1000,
};

this.axiosMock
.expects('post')
.expects("post")
.withArgs(serverUrl, {
jsonrpc: '2.0',
jsonrpc: "2.0",
id: 1,
method: 'getLedgerEntries',
params: [[ledgerKey.toXDR('base64')]]
method: "getLedgerEntries",
params: [[ledgerKey.toXDR("base64")]],
})
.returns(
Promise.resolve({
Expand All @@ -66,59 +66,59 @@ describe('Server#getContractData', function () {
{
liveUntilLedgerSeq: ledgerTtlEntry.ttl().liveUntilLedgerSeq(),
lastModifiedLedgerSeq: result.lastModifiedLedgerSeq,
key: ledgerKey.toXDR('base64'),
xdr: ledgerEntry.toXDR('base64')
}
]
}
}
})
key: ledgerKey.toXDR("base64"),
xdr: ledgerEntry.toXDR("base64"),
},
],
},
},
}),
);

this.server
.getContractData(address, key, Durability.Persistent)
.then(function (response) {
expect(response.key.toXDR('base64')).to.eql(result.key.toXDR('base64'));
expect(response.val.toXDR('base64')).to.eql(result.val.toXDR('base64'));
expect(response.key.toXDR("base64")).to.eql(result.key.toXDR("base64"));
expect(response.val.toXDR("base64")).to.eql(result.val.toXDR("base64"));
expect(response.liveUntilLedgerSeq).to.eql(1000);
done();
})
.catch((err) => done(err));
});

it('contract data key not found', function (done) {
it("contract data key not found", function (done) {
// clone and change durability to test this case
const ledgerKeyDupe = xdr.LedgerKey.fromXDR(ledgerKey.toXDR());
ledgerKeyDupe
.contractData()
.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')]]
method: "getLedgerEntries",
params: [[ledgerKeyDupe.toXDR("base64")]],
})
.returns(Promise.resolve({ data: { result: { entries: [] } } }));

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
2 changes: 1 addition & 1 deletion test/unit/server/soroban/get_events_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ let getEventsResponseFixture = [
pagingToken: "164090849041387521-3",
inSuccessfulContractCall: true,
topic: topicVals.slice(0, 2),
value: eventVal
value: eventVal,
},
{
type: "diagnostic",
Expand Down
Loading

0 comments on commit 5d945c6

Please sign in to comment.