Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow account create operation with zero balance. #375

Merged
merged 2 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 src/operations/create_account.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function createAccount(opts) {
if (!StrKey.isValidEd25519PublicKey(opts.destination)) {
throw new Error('destination is invalid');
}
if (!this.isValidAmount(opts.startingBalance)) {
if (!this.isValidAmount(opts.startingBalance, true)) {
throw new TypeError(
this.constructAmountRequirementsError('startingBalance')
);
Expand Down
11 changes: 11 additions & 0 deletions test/unit/operation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ describe('Operation', function() {
);
});

it('creates a createAccount operation with startingBalance equal to 0', function() {
let opts = {
destination: 'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ',
startingBalance: '0',
source: 'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ'
};
expect(() => StellarBase.Operation.createAccount(opts)).not.to.throw(
/startingBalance argument must be of type String, represent a positive number and have at most 7 digits after the decimal/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we change this error msg too (include zero).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can say "non-negative" instead of "positive" to include >= 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message updated 4efa3a8

);
});

it('fails to create createAccount operation with an invalid startingBalance', function() {
let opts = {
destination: 'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ',
Expand Down