forked from Shell-Protocol/Shell-Protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimitive.js
More file actions
62 lines (53 loc) · 2.17 KB
/
Primitive.js
File metadata and controls
62 lines (53 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const { ethers } = require("hardhat")
const { expect } = require("chai")
const shellV2 = require("../utils-js");
describe("Primitive Tests", () => {
let ocean
let alice
let bob
before("Deploy Ocean", async () => {
[alice, bob] = await ethers.getSigners()
const oceanContract = await ethers.getContractFactory("Ocean", bob)
ocean = await oceanContract.deploy("")
})
it("Can create a new shell", async () => {
const txData = await ocean.connect(alice).registerNewTokens(0, 1)
const txReceipt = await txData.wait(1)
const decodedData = txReceipt.events[0].decode(txReceipt.events[0].data)
const newShell = ethers.utils.hexlify(decodedData.tokens[0])
const expectedNewShell = shellV2.utils.calculateWrappedTokenId({
address: alice.address,
id: 0
})
expect(newShell).to.equal(expectedNewShell)
})
it("Can register 100 new Tokens", async () => {
const currentNumber = 1
const additional = 100
const txData = await ocean.connect(alice)
.registerNewTokens(currentNumber, additional)
const txReceipt = await txData.wait(1)
const decodedData = txReceipt.events[0].decode(txReceipt.events[0].data)
const Tokens = decodedData.tokens.map((token) => ethers.utils.hexlify(token))
Tokens.map((shell, index) => {
const expectedToken = shellV2.utils.calculateWrappedTokenId({
address: alice.address,
id: currentNumber + index
})
expect(shell).to.equal(expectedToken)
})
})
it("Can create shell with random nonce", async () => {
const nonce = 1298401938
const txData = await ocean.connect(alice)
.registerNewTokens(1298401938, 1)
const txReceipt = await txData.wait(1)
const decodedData = txReceipt.events[0].decode(txReceipt.events[0].data)
const shell = ethers.utils.hexlify(decodedData.tokens[0])
const expectedShell = shellV2.utils.calculateWrappedTokenId({
address: alice.address,
id: nonce
})
expect(shell).to.equal(expectedShell)
})
})