Skip to content

Commit

Permalink
Merge branch 'main' into importer
Browse files Browse the repository at this point in the history
  • Loading branch information
Scooletz committed Nov 5, 2024
2 parents f3ed855 + e6c04bf commit fac80d3
Show file tree
Hide file tree
Showing 6 changed files with 535 additions and 187 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/dependency_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 #v4.2.0
- name: 'Dependency Review'
uses: actions/dependency-review-action@4081bf99e2866ebe428fc0477b69eb4fcda7220a #v4.4.0
with:
fail-on-severity: high
75 changes: 75 additions & 0 deletions src/Paprika.Tests/Chain/RawStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,79 @@ public async Task DeleteByPrefix()
using var read = db.BeginReadOnlyBatch();
read.TryGet(Key.Account(account), out _).Should().BeFalse();
}

[Test]
public async Task DeleteByShortPrefix()
{
var account1 = new Keccak(new byte[]
{ 1, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, });

var account2 = new Keccak(new byte[]
{ 18, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, });

using var db = PagedDb.NativeMemoryDb(64 * 1024, 2);
var merkle = new ComputeMerkleBehavior();

await using var blockchain = new Blockchain(db, merkle);

using var raw = blockchain.StartRaw();

raw.SetAccount(account1, new Account(1, 1));
raw.SetAccount(account2, new Account(2, 2));
raw.Commit();

raw.RegisterDeleteByPrefix(Key.Account(NibblePath.FromKey(account2).SliceTo(1)));
raw.Commit();

raw.Finalize(1);

//check account 1 is still present and account 2 is deleted
using var read = db.BeginReadOnlyBatch();
read.TryGet(Key.Account(account1), out _).Should().BeTrue();
read.TryGet(Key.Account(account2), out _).Should().BeFalse();

//let's re-add 2nd account and delete using empty prefix
using var raw2 = blockchain.StartRaw();

raw2.SetAccount(account2, new Account(2, 2));
raw2.Commit();

raw2.RegisterDeleteByPrefix(Key.Account(NibblePath.Empty));
raw2.Commit();

raw2.Finalize(2);

//no accounts should be present
using var read2 = db.BeginReadOnlyBatch();
read2.TryGet(Key.Account(account1), out _).Should().BeFalse();
read2.TryGet(Key.Account(account2), out _).Should().BeFalse();
}

[Test]
public void DeleteByPrefixStorage()
{
var account = Values.Key1;

using var db = PagedDb.NativeMemoryDb(256 * 1024, 2);
var merkle = new ComputeMerkleBehavior();

var blockchain = new Blockchain(db, merkle);

using var raw = blockchain.StartRaw();

raw.SetAccount(account, new Account(1, 1));
raw.SetStorage(account, Values.Key2, new byte[] { 1, 2, 3, 4, 5 });
raw.Commit();

using var read = db.BeginReadOnlyBatch();
read.TryGet(Key.StorageCell(NibblePath.FromKey(account), Values.Key2), out _).Should().BeTrue();

raw.RegisterDeleteByPrefix(Key.StorageCell(NibblePath.FromKey(account), NibblePath.Empty));
raw.Commit();

raw.Finalize(1);

using var read2 = db.BeginReadOnlyBatch();
read2.TryGet(Key.StorageCell(NibblePath.FromKey(account), Values.Key2), out _).Should().BeFalse();
}
}
Loading

0 comments on commit fac80d3

Please sign in to comment.