Skip to content

Commit

Permalink
Merge pull request #499 from BoostryJP/fix/checkpoint_locked_balance
Browse files Browse the repository at this point in the history
fix: set previous locked balance when checkpoint is used
  • Loading branch information
YoshihitoAso authored Mar 22, 2023
2 parents ca36630 + 14acd9e commit 71a3222
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion batch/indexer_token_holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def __load_checkpoint(
)
for holder in _holders:
self.balance_book.store(
account_address=holder.account_address, amount=holder.hold_balance
account_address=holder.account_address,
amount=holder.hold_balance,
locked=holder.locked_balance,
)
block_from = _checkpoint.block_number + 1
return block_from
Expand Down
22 changes: 20 additions & 2 deletions tests/test_batch_indexer_token_holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,9 @@ def test_normal_3(
)

assert user1_record.hold_balance == 17000
assert user1_record.locked_balance == 0
assert user2_record.hold_balance == 13000
assert user2_record.locked_balance == 0

assert (
len(
Expand Down Expand Up @@ -1701,7 +1703,9 @@ def test_normal_6(
)

assert user1_record.hold_balance == 17000
assert user1_record.locked_balance == 0
assert user2_record.hold_balance == 13000
assert user2_record.locked_balance == 0

assert (
len(
Expand Down Expand Up @@ -1916,6 +1920,12 @@ def test_normal_8(
issuer_private_key,
[exchange_contract.address, 10000],
)
STContractUtils.lock(
token_contract.address,
user_address_1,
user_pk_1,
[issuer_address, 10000, ""],
)

# Insert collection record with above token and current block number
list_id = str(uuid.uuid4())
Expand All @@ -1927,6 +1937,12 @@ def test_normal_8(
db.commit()
processor.collect()

STContractUtils.unlock(
token_contract.address,
issuer_address,
issuer_private_key,
[user_address_1, user_address_2, 10000, ""],
)
STContractUtils.transfer(
token_contract.address,
issuer_address,
Expand Down Expand Up @@ -1969,8 +1985,10 @@ def test_normal_8(
.first()
)

assert user1_record.hold_balance == 40000
assert user2_record.hold_balance == 20000
assert user1_record.hold_balance == 30000
assert user1_record.locked_balance == 0
assert user2_record.hold_balance == 30000
assert user2_record.locked_balance == 0

assert (
len(
Expand Down

0 comments on commit 71a3222

Please sign in to comment.