Skip to content

Commit

Permalink
WIP: Address all renames so that tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Oct 16, 2023
1 parent 16fd621 commit 83e57c5
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 51 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

## Unreleased

### Fixed
- The type definition for `Memo.hash` now allows `Buffer`s ([#698](https://github.com/stellar/js-stellar-base/pull/698)).

* XDR has been upgraded to the latest stable version ([stellar-xdr@`6a620d1`](https://github.com/stellar/stellar-xdr/tree/6a620d160aab22609c982d54578ff6a63bfcdc01)). This is mostly renames, but it includes the following relevant breaking changes ([]()):
- TODO.

## [`v10.0.0-beta.3`](https://github.com/stellar/js-stellar-base/compare/v10.0.0-beta.2...v10.0.0-beta.3)

Expand Down
4 changes: 2 additions & 2 deletions config/prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module.exports = {
printWidth: 80,
proseWrap: 'always',
semi: true,
singleQuote: false,
singleQuote: true,
tabWidth: 2,
parser: 'babel',
trailingComma: 'es5',
trailingComma: 'none',
useTabs: false
};
2 changes: 1 addition & 1 deletion src/invocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function buildInvocationTree(root) {
break;
}

// contractExecutableToken
// contractExecutableStellarAsset
case 1:
output.args.type = 'sac';
output.args.asset = Asset.fromOperation(
Expand Down
10 changes: 5 additions & 5 deletions src/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const AuthClawbackEnabledFlag = 1 << 3;
* * `{@link Operation.liquidityPoolDeposit}`
* * `{@link Operation.liquidityPoolWithdraw}`
* * `{@link Operation.invokeHostFunction}`
* * `{@link Operation.bumpFootprintExpiration}`
* * `{@link Operation.extendFootprintTtlOp}`
* * `{@link Operation.restoreFootprint}`
*
* @class Operation
Expand Down Expand Up @@ -381,9 +381,9 @@ export class Operation {
result.auth = attrs.auth() ?? [];
break;
}
case 'bumpFootprintExpiration': {
result.type = 'bumpFootprintExpiration';
result.ledgersToExpire = attrs.ledgersToExpire();
case 'extendFootprintTtl': {
result.type = 'extendFootprintTtl';
result.extendTo = attrs.extendTo();
break;
}
case 'restoreFootprint': {
Expand Down Expand Up @@ -672,5 +672,5 @@ Operation.setTrustLineFlags = ops.setTrustLineFlags;
Operation.liquidityPoolDeposit = ops.liquidityPoolDeposit;
Operation.liquidityPoolWithdraw = ops.liquidityPoolWithdraw;
Operation.invokeHostFunction = ops.invokeHostFunction;
Operation.bumpFootprintExpiration = ops.bumpFootprintExpiration;
Operation.extendFootprintTtlOp = ops.extendFootprintTtlOp;
Operation.restoreFootprint = ops.restoreFootprint;
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ import xdr from '../xdr';
* usage as part of {@link xdr.SorobanResources}).
*
* @function
* @alias Operation.bumpFootprintExpiration
* @alias Operation.extendFootprintTtlOp
*
* @param {object} opts - object holding operation parameters
* @param {number} opts.ledgersToExpire - the number of ledgers past the LCL
* @param {number} opts.extendTo - the number of ledgers past the LCL
* (last closed ledger) by which to extend the validity of the ledger keys in
* this transaction
* @param {string} [opts.source] - an optional source account
*
* @returns {xdr.Operation} a Bump Footprint Expiration operation
* (xdr.BumpFootprintExpirationOp)
* (xdr.ExtendFootprintTTLOp)
*/
export function bumpFootprintExpiration(opts) {
if ((opts.ledgersToExpire ?? -1) <= 0) {
throw new RangeError("ledgersToExpire isn't a ledger quantity (uint32)");
export function extendFootprintTtlOp(opts) {
if ((opts.extendTo ?? -1) <= 0) {
throw new RangeError("extendTo isn't a ledger quantity (uint32)");
}

const bumpFootprintOp = new xdr.BumpFootprintExpirationOp({
const bumpFootprintOp = new xdr.ExtendFootprintTtlOp({
ext: new xdr.ExtensionPoint(0),
ledgersToExpire: opts.ledgersToExpire
extendTo: opts.extendTo
});

const opAttributes = {
body: xdr.OperationBody.bumpFootprintExpiration(bumpFootprintOp)
body: xdr.OperationBody.extendFootprintTtl(bumpFootprintOp)
};
this.setSourceAccount(opAttributes, opts);

Expand Down
2 changes: 1 addition & 1 deletion src/operations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export { setTrustLineFlags } from './set_trustline_flags';
export { liquidityPoolDeposit } from './liquidity_pool_deposit';
export { liquidityPoolWithdraw } from './liquidity_pool_withdraw';
export { invokeHostFunction } from './invoke_host_function';
export { bumpFootprintExpiration } from './bump_footprint_expiration';
export { extendFootprintTtlOp } from './extend_footprint_ttl_op';
export { restoreFootprint } from './restore_footprint';
11 changes: 5 additions & 6 deletions src/sorobandata_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import xdr from './xdr';
* items set to specific values.
*
* This is recommended for when you are building
* {@link Operation.bumpFootprintExpiration} /
* {@link Operation.restoreFootprint} operations and need to
* {@link TransactionBuilder.setSorobanData} to avoid (re)building the entire
* data structure from scratch.
* {@link Operation.extendFootprintTtlOp} / {@link Operation.restoreFootprint}
* operations and need to {@link TransactionBuilder.setSorobanData} to avoid
* (re)building the entire data structure from scratch.
*
* @constructor
*
Expand Down Expand Up @@ -46,7 +45,7 @@ export class SorobanDataBuilder {
writeBytes: 0
}),
ext: new xdr.ExtensionPoint(0),
refundableFee: new xdr.Int64(0)
resourceFee: new xdr.Int64(0)
});
} else if (
typeof sorobanData === 'string' ||
Expand Down Expand Up @@ -78,7 +77,7 @@ export class SorobanDataBuilder {
* @returns {SorobanDataBuilder}
*/
setRefundableFee(fee) {
this._data.refundableFee(new xdr.Int64(fee));
this._data.resourceFee(new xdr.Int64(fee));
return this;
}

Expand Down
3 changes: 2 additions & 1 deletion test/unit/invocation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ describe('parsing invocation trees', function () {
xdr.ContractIdPreimage.contractIdPreimageFromAsset(
new Asset('TEST', nftId).toXDRObject()
),
executable: xdr.ContractExecutable.contractExecutableToken()
executable:
xdr.ContractExecutable.contractExecutableStellarAsset()
})
),
subInvocations: []
Expand Down
18 changes: 8 additions & 10 deletions test/unit/operation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2047,24 +2047,22 @@ describe('Operation', function () {
});
});

describe('bumpFootprintExpiration()', function () {
describe('extendFootprintTtlOp()', function () {
it('creates operation', function () {
const op = StellarBase.Operation.bumpFootprintExpiration({
ledgersToExpire: 1234
const op = StellarBase.Operation.extendFootprintTtlOp({
extendTo: 1234
});
const xdr = op.toXDR('hex');
const operation = StellarBase.xdr.Operation.fromXDR(xdr, 'hex');

expect(operation.body().switch().name).to.equal(
'bumpFootprintExpiration'
);
expect(operation.body().switch().name).to.equal('extendFootprintTtl');
const obj = StellarBase.Operation.fromXDRObject(operation);
expect(obj.type).to.be.equal('bumpFootprintExpiration');
expect(obj.ledgersToExpire).to.equal(1234);
expect(obj.type).to.be.equal('extendFootprintTtlOp');
expect(obj.extendTo).to.equal(1234);

expect(() => {
StellarBase.Operation.bumpFootprintExpiration({
ledgersToExpire: 0
StellarBase.Operation.extendFootprintTtlOp({
extendTo: 0
});
}).to.throw(/ledger quantity/i);
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/sorobandata_builder_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('SorobanTransactionData can be built', function () {
writeBytes: 3
}),
ext: new xdr.ExtensionPoint(0),
refundableFee: new xdr.Int64(5)
resourceFee: new xdr.Int64(5)
});

const key = c.getFootprint()[0];
Expand Down Expand Up @@ -75,6 +75,6 @@ describe('SorobanTransactionData can be built', function () {
const first = builder.build();
const second = builder.setRefundableFee(100).build();

expect(first.refundableFee()).to.not.eql(second.refundableFee());
expect(first.resourceFee()).to.not.eql(second.resourceFee());
});
});
22 changes: 11 additions & 11 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export namespace OperationType {
type LiquidityPoolDeposit = 'liquidityPoolDeposit';
type LiquidityPoolWithdraw = 'liquidityPoolWithdraw';
type InvokeHostFunction = 'invokeHostFunction';
type BumpFootprintExpiration = 'bumpFootprintExpiration';
type ExtendFootprintTTLOp = 'extendFootprintTtlOp';
type RestoreFootprint = 'restoreFootprint';
}
export type OperationType =
Expand Down Expand Up @@ -398,7 +398,7 @@ export type OperationType =
| OperationType.LiquidityPoolDeposit
| OperationType.LiquidityPoolWithdraw
| OperationType.InvokeHostFunction
| OperationType.BumpFootprintExpiration
| OperationType.ExtendFootprintTTLOp
| OperationType.RestoreFootprint;

export namespace OperationOptions {
Expand Down Expand Up @@ -550,8 +550,8 @@ export namespace OperationOptions {
func: xdr.HostFunction;
auth: xdr.SorobanAuthorizationEntry[];
}
interface BumpFootprintExpiration extends BaseOptions {
ledgersToExpire: number;
interface ExtendFootprintTTLOp extends BaseOptions {
extendTo: number;
}
type RestoreFootprint = BaseOptions;
}
Expand Down Expand Up @@ -586,7 +586,7 @@ export type OperationOptions =
| OperationOptions.LiquidityPoolDeposit
| OperationOptions.LiquidityPoolWithdraw
| OperationOptions.InvokeHostFunction
| OperationOptions.BumpFootprintExpiration
| OperationOptions.ExtendFootprintTTLOp
| OperationOptions.RestoreFootprint;

export namespace Operation {
Expand Down Expand Up @@ -876,11 +876,11 @@ export namespace Operation {
options: OperationOptions.InvokeHostFunction
): xdr.Operation<InvokeHostFunction>;

function bumpFootprintExpiration(
options: OperationOptions.BumpFootprintExpiration
): xdr.Operation<BumpFootprintExpiration>;
interface BumpFootprintExpiration extends BaseOperation<OperationType.BumpFootprintExpiration> {
ledgersToExpire: number;
function extendFootprintTtlOp(
options: OperationOptions.ExtendFootprintTTLOp
): xdr.Operation<ExtendFootprintTTLOp>;
interface ExtendFootprintTTLOp extends BaseOperation<OperationType.ExtendFootprintTTLOp> {
extendTo: number;
}

function restoreFootprint(options: OperationOptions.RestoreFootprint):
Expand Down Expand Up @@ -923,7 +923,7 @@ export type Operation =
| Operation.LiquidityPoolDeposit
| Operation.LiquidityPoolWithdraw
| Operation.InvokeHostFunction
| Operation.BumpFootprintExpiration
| Operation.ExtendFootprintTTLOp
| Operation.RestoreFootprint;

export namespace StrKey {
Expand Down

0 comments on commit 83e57c5

Please sign in to comment.