public void Repository_CacheDoesntCarryOver() { const string testContractType = "A String"; ISource <byte[], byte[]> stateDB = new NoDeleteSource <byte[], byte[]>(new MemoryDictionarySource()); StateRepositoryRoot repository = new StateRepositoryRoot(stateDB); byte[] initialRoot = repository.Root; IStateRepository txTrack = repository.StartTracking(); txTrack.CreateAccount(testAddress); txTrack.SetStorageValue(testAddress, dog, cat); txTrack.SetContractType(testAddress, testContractType); txTrack.Commit(); repository.Commit(); byte[] postChangesRoot = repository.Root; IStateRepositoryRoot repository2 = repository.GetSnapshotTo(initialRoot); Assert.Null(repository2.GetAccountState(testAddress)); repository2.SetContractType(testAddress, "Something Else"); repository2.SyncToRoot(postChangesRoot); Assert.Equal(testContractType, repository2.GetContractType(testAddress)); }
public void Repository_CommitAndRollbackTest() { ISource <byte[], byte[]> stateDB = new NoDeleteSource <byte[], byte[]>(new MemoryDictionarySource()); StateRepositoryRoot repository = new StateRepositoryRoot(stateDB); IStateRepository txTrack = repository.StartTracking(); txTrack.CreateAccount(testAddress); txTrack.SetStorageValue(testAddress, dog, cat); txTrack.Commit(); repository.Commit(); byte[] root1 = repository.Root; IStateRepository txTrack2 = repository.StartTracking(); txTrack2.SetStorageValue(testAddress, dog, fish); txTrack2.Rollback(); IStateRepository txTrack3 = repository.StartTracking(); txTrack3.SetStorageValue(testAddress, dodecahedron, bird); txTrack3.Commit(); repository.Commit(); byte[] upToDateRoot = repository.Root; Assert.Equal(cat, repository.GetStorageValue(testAddress, dog)); Assert.Equal(bird, repository.GetStorageValue(testAddress, dodecahedron)); IStateRepository snapshot = repository.GetSnapshotTo(root1); repository.SyncToRoot(root1); Assert.Equal(cat, snapshot.GetStorageValue(testAddress, dog)); Assert.Null(snapshot.GetStorageValue(testAddress, dodecahedron)); }