Skip to content

Commit

Permalink
fix: identity create balance validation
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Oct 30, 2023
1 parent 4e0eeb6 commit 7b73a06
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ const {
IdentityPublicKey,
InvalidInstantAssetLockProofSignatureError,
IdentityAssetLockTransactionOutPointAlreadyExistsError,
BalanceIsNotEnoughError,
BasicECDSAError,
IdentityPublicKeyWithWitness,
IdentityInsufficientBalanceError,
},
} = Dash;

describe('Platform',() => {
describe('Platform', () => {
describe('Identity', function describeIdentity() {
this.bail(true); // bail on first failure

Expand Down Expand Up @@ -103,7 +102,7 @@ describe('Platform',() => {
transaction,
privateKey,
outputIndex,
} = await client.platform.identities.utils.createAssetLockTransaction(100000);
} = await client.platform.identities.utils.createAssetLockTransaction(150000);

const account = await client.getWalletAccount();

Expand Down Expand Up @@ -248,7 +247,7 @@ describe('Platform',() => {
transaction,
privateKey,
outputIndex,
} = await client.platform.identities.utils.createAssetLockTransaction(100000);
} = await client.platform.identities.utils.createAssetLockTransaction(150000);

const account = await client.getWalletAccount();

Expand Down Expand Up @@ -325,9 +324,11 @@ describe('Platform',() => {
});
});

// TODO: there is a bug in identity create balance validation
it.skip('should fail to create more documents if there are no more credits', async () => {
const lowBalanceIdentity = await client.platform.identities.register(80000);
it('should fail to create more documents if there are no more credits', async () => {
const lowBalanceIdentity = await client.platform.identities.register(150000);

// Additional wait time to mitigate testnet latency
await waitForSTPropagated();

const document = await client.platform.documents.create(
'customContracts.niceDocument',
Expand All @@ -350,7 +351,7 @@ describe('Platform',() => {
expect(broadcastError).to.exist();
expect(broadcastError).to.be.an.instanceOf(StateTransitionBroadcastError);
expect(broadcastError.getCause()).to.be.an.instanceOf(
BalanceIsNotEnoughError,
IdentityInsufficientBalanceError,
);
});

Expand Down Expand Up @@ -458,7 +459,10 @@ describe('Platform',() => {

// Creating ST that tries to spend the same output

const anotherIdentity = await client.platform.identities.register(100000);
const anotherIdentity = await client.platform.identities.register(150000);

// Additional wait time to mitigate testnet latency
await waitForSTPropagated();

const conflictingTopUpStateTransition = await client.platform.identities.utils
.createIdentityTopUpTransition(assetLockProof, privateKey, anotherIdentity.getId());
Expand Down Expand Up @@ -490,6 +494,8 @@ describe('Platform',() => {
let recipient;
before(async () => {
recipient = await client.platform.identities.register(400000);

// Additional wait time to mitigate testnet latency
await waitForSTPropagated();
});

Expand All @@ -510,6 +516,7 @@ describe('Platform',() => {
transferAmount,
);

// Additional wait time to mitigate testnet latency
await waitForSTPropagated();

const identityAfterTransfer = await client.platform.identities.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Platform', () => {
await hashFunction.init();
blake3 = hashFunction.hashFunction;

dashClient = await createClientWithFundedWallet(400000);
dashClient = await createClientWithFundedWallet(500000);

await dashClient.platform.initialize();

Expand Down Expand Up @@ -137,11 +137,11 @@ describe('Platform', () => {
let identity8PublicKeyHash;

before(async () => {
identityAtKey5 = await dashClient.platform.identities.register(100000);
identityAtKey5 = await dashClient.platform.identities.register(150000);

identityAtKey6 = await dashClient.platform.identities.register(100000);
identityAtKey6 = await dashClient.platform.identities.register(150000);

identityAtKey8 = await dashClient.platform.identities.register(100000);
identityAtKey8 = await dashClient.platform.identities.register(150000);

// await waitForBalanceToChange(walletAccount);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ impl<'a> ExecutionEvent<'a> {
match &action {
StateTransitionAction::IdentityCreateAction(identity_create_action) => {
let identity = identity_create_action.into();
let added_balance = identity_create_action.initial_balance_amount();
let operations =
action.into_high_level_drive_operations(epoch, platform_version)?;
Ok(PaidFromAssetLockDriveEvent {
identity,
added_balance,
added_balance: 0,
operations,
})
}
Expand Down

0 comments on commit 7b73a06

Please sign in to comment.