Skip to content

Commit

Permalink
Run yarn fmt (some overlap with #763)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Jul 18, 2024
1 parent 56e56c7 commit 86e9ff3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function extractEvent(event) {
return {
...(event.contractId != null &&
event.contractId() != null && {
contractId: StrKey.encodeContract(event.contractId())
}),
contractId: StrKey.encodeContract(event.contractId())
}),
type: event.type().name,
topics: event
.body()
Expand Down
4 changes: 2 additions & 2 deletions src/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ export class TransactionBuilder {
addOperation(operation) {
this.operations.push(operation);
return this;
}
}

/**
* Adds an operation to the transaction at a specific index.
*
Expand Down
79 changes: 44 additions & 35 deletions test/unit/transaction_builder_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,51 +956,60 @@ describe('TransactionBuilder', function () {
});

it('adds operations at a specific index', function () {
const builder = new StellarBase.TransactionBuilder(source, {
fee: '100',
timebounds: { minTime: 0, maxTime: 0 },
memo: new StellarBase.Memo(StellarBase.MemoText, 'Testing adding op at index'),
networkPassphrase
});
const builder = new StellarBase.TransactionBuilder(source, {
fee: '100',
timebounds: { minTime: 0, maxTime: 0 },
memo: new StellarBase.Memo(
StellarBase.MemoText,
'Testing adding op at index'
),
networkPassphrase
});

builder.addOperationAt(StellarBase.Operation.payment({
builder.addOperationAt(
StellarBase.Operation.payment({
source: source.accountId(),
destination: destination,
amount: '1',
asset: asset
}), 0);
}),
0
);

builder.addOperationAt(StellarBase.Operation.payment({
builder.addOperationAt(
StellarBase.Operation.payment({
source: source.accountId(),
destination: destination,
amount: '2',
asset: asset
}), 1);

const tx = builder.build();
// Assert operations
expect(tx.operations.length).to.equal(2);
expect(tx.operations[0].source).to.equal(source.accountId());
expect(parseInt(tx.operations[0].amount)).to.equal(1);
expect(tx.operations[1].source).to.equal(source.accountId());
expect(parseInt(tx.operations[1].amount)).to.equal(2);

const clonedTx = StellarBase.TransactionBuilder.cloneFrom(tx)
clonedTx.clearOperationAt(0);
const newOperation = StellarBase.Operation.payment({
source: source.accountId(),
destination: destination,
amount: '3',
asset: asset
})
clonedTx.addOperationAt(newOperation, 0);
const newTx = clonedTx.build()
// Assert that the operations are the same, but the first one is updated
expect(newTx.operations.length).to.equal(2);
expect(newTx.operations[0].source).to.equal(source.accountId());
expect(parseInt(newTx.operations[0].amount)).to.equal(3);
expect(newTx.operations[1].source).to.equal(source.accountId());
expect(parseInt(newTx.operations[1].amount)).to.equal(2);
}),
1
);

const tx = builder.build();
// Assert operations
expect(tx.operations.length).to.equal(2);
expect(tx.operations[0].source).to.equal(source.accountId());
expect(parseInt(tx.operations[0].amount)).to.equal(1);
expect(tx.operations[1].source).to.equal(source.accountId());
expect(parseInt(tx.operations[1].amount)).to.equal(2);

const clonedTx = StellarBase.TransactionBuilder.cloneFrom(tx);
clonedTx.clearOperationAt(0);
const newOperation = StellarBase.Operation.payment({
source: source.accountId(),
destination: destination,
amount: '3',
asset: asset
});
clonedTx.addOperationAt(newOperation, 0);
const newTx = clonedTx.build();
// Assert that the operations are the same, but the first one is updated
expect(newTx.operations.length).to.equal(2);
expect(newTx.operations[0].source).to.equal(source.accountId());
expect(parseInt(newTx.operations[0].amount)).to.equal(3);
expect(newTx.operations[1].source).to.equal(source.accountId());
expect(parseInt(newTx.operations[1].amount)).to.equal(2);
});
});
});

0 comments on commit 86e9ff3

Please sign in to comment.