Skip to content

Commit

Permalink
Allow account create operation with zero balance. (stellar#375)
Browse files Browse the repository at this point in the history
* Allow account create operation with zero balance.

* Update error message for invalid startingBalance in createAccountOp.
  • Loading branch information
abuiles committed Oct 22, 2020
1 parent c0c1895 commit eef8a9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/operations/create_account.js
Expand Up @@ -17,9 +17,9 @@ 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')
'startingBalance must be of type String, represent a non-negative number and have at most 7 digits after the decimal'
);
}
const attributes = {};
Expand Down
13 changes: 12 additions & 1 deletion test/unit/operation_test.js
Expand Up @@ -39,14 +39,25 @@ 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 must be of type String, represent a non-negative number and have at most 7 digits after the decimal/
);
});

it('fails to create createAccount operation with an invalid startingBalance', function() {
let opts = {
destination: 'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ',
startingBalance: 20,
source: 'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ'
};
expect(() => StellarBase.Operation.createAccount(opts)).to.throw(
/startingBalance argument must be of type String, represent a positive number and have at most 7 digits after the decimal/
/startingBalance must be of type String, represent a non-negative number and have at most 7 digits after the decimal/
);
});

Expand Down

0 comments on commit eef8a9a

Please sign in to comment.