epam / mintgate

1 stars 2 forks source link

Only one token created if `claim_token` called several times simultaneously #71

Closed sxurik closed 3 years ago

sxurik commented 3 years ago

Claiming several tokens like this:

await Promise.all([
  bob.contract.claim_token({ gate_id: someGateId }),
  bob.contract.claim_token({ gate_id: someGateId }),
]);

should mint 2 tokens.

But for some reason only one token gets minted and added, all calls to claim_token return the same token_id. The same happens when making for example 5 calls instead of 2 - only 1 token is minted.

Making 4 calls from 2 different accounts:

await Promise.all([
  bob.contract.claim_token({ gate_id: someGateId }),
  alice.contract.claim_token({ gate_id: someGateId }),
  bob.contract.claim_token({ gate_id: someGateId }),
  alice.contract.claim_token({ gate_id: someGateId }),
]);

results in 2 tokens being created instead of 4.

But if there were some method-calls on the contract recently, claim_token from this contract works correctly.

So this code:

await alice.contract.create_collectible({ ... });

await Promise.all([
  bob.contract.claim_token({ gate_id: someGateId }),
  alice.contract.claim_token({ gate_id: someGateId }),
  bob.contract.claim_token({ gate_id: someGateId }),
  alice.contract.claim_token({ gate_id: someGateId }),
]);

mints 2 tokens for alice (which is expected) and 1 token for bob (instead of 2).

zahhar commented 3 years ago

However, this results in 2 tokens claimed:

await Promise.all([
  bob.contract.claim_token({ gate_id: someGateId })
]);

await Promise.all([
  bob.contract.claim_token({ gate_id: someGateId })
]);