-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from freespek/igor/storage
add a simple implementation of ADR002
- Loading branch information
Showing
2 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Storage tests. | ||
* | ||
* Igor Konnov, 2024 | ||
*/ | ||
|
||
import { assert } from 'chai' | ||
import { mkdtempSync } from 'fs' | ||
import { describe, it } from 'mocha' | ||
import { tmpdir } from 'node:os' | ||
import { join } from 'node:path' | ||
import { | ||
loadContractCallEntry, | ||
saveContractCallEntry, | ||
} from '../../src/fetcher/storage.js' | ||
import { OrderedMap } from 'immutable' | ||
|
||
const TX_HASH = | ||
'9fb12935fbadcd28aa220d076f11be631590d22c60977a53997a746898322ca3' | ||
const CONTRACT_ID = 'CC22QGTOUMERDNIYN7TPNX3V6EMPHQXVSRR3XY56EADF7YTFISD2ROND' | ||
|
||
describe('storage tests', () => { | ||
function storeEntry() { | ||
const root = join(tmpdir(), 'solarkraft-storage-') | ||
mkdtempSync(root) | ||
const filename = saveContractCallEntry(root, { | ||
height: 1000, | ||
txHash: TX_HASH, | ||
contractId: CONTRACT_ID, | ||
method: 'set_i32', | ||
methodArgs: [42], | ||
returnValue: 0, | ||
fields: OrderedMap<string, any>([ | ||
['a', 3], | ||
['b', 993143214321423154315154321n], | ||
]), | ||
oldFields: OrderedMap<string, any>([ | ||
['a', 1], | ||
['b', 993143214321423154315154322n], | ||
]), | ||
}) | ||
|
||
return [root, filename] | ||
} | ||
|
||
it('store entry', async () => { | ||
const [root, filename] = storeEntry() | ||
|
||
assert.equal( | ||
filename, | ||
join(root, CONTRACT_ID, '1000', `entry-${TX_HASH}.json`) | ||
) | ||
}) | ||
|
||
it('load entry', async () => { | ||
const filename = storeEntry()[1] | ||
const entry = loadContractCallEntry(filename) | ||
assert.equal(entry.height, 1000) | ||
assert.equal(entry.txHash, TX_HASH) | ||
assert.equal(entry.contractId, CONTRACT_ID) | ||
assert.equal(entry.method, 'set_i32') | ||
assert.deepEqual(entry.methodArgs, [42]) | ||
assert.equal(entry.returnValue, 0) | ||
assert.deepEqual(entry.fields.toArray(), [ | ||
['a', 3], | ||
['b', 993143214321423154315154321n], | ||
]) | ||
assert.deepEqual(entry.oldFields.toArray(), [ | ||
['a', 1], | ||
['b', 993143214321423154315154322n], | ||
]) | ||
}) | ||
}) |