@alephium/web3 0.2.0-rc.1 → 0.2.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,9 +133,9 @@ describe('contract', function () {
133
133
  it('should test buildScriptByteCode', async () => {
134
134
  const variables = { x: true, y: 0x05, z: 'ff', a: '1C2RAVWSuaXw8xtUxqVERR7ChKBE1XgscNFw73NSHE1v3' }
135
135
  const fieldsSig: node.FieldsSig = {
136
- signature: 'Not really',
137
136
  names: ['x', 'y', 'z', 'a'],
138
- types: ['Bool', 'U256', 'ByteVec', 'Address']
137
+ types: ['Bool', 'U256', 'ByteVec', 'Address'],
138
+ isMutable: [false, false, false, false]
139
139
  }
140
140
  const bytecode = ralph.buildScriptByteCode('-{0}-{1}-{2}-{3}-', variables, fieldsSig)
141
141
  expect(bytecode).toEqual('-03-1305-1401ff-1500a3cd757be03c7dac8d48bf79e2a7d6e735e018a9c054b99138c7b29738c437ec-')
@@ -150,9 +150,9 @@ describe('contract', function () {
150
150
  e: [false, true]
151
151
  }
152
152
  const fieldsSig: node.FieldsSig = {
153
- signature: 'Not really',
154
153
  names: ['a', 'b', 'c', 'd', 'e'],
155
- types: ['I256', 'U256', 'ByteVec', 'Address', '[Bool;2]']
154
+ types: ['I256', 'U256', 'ByteVec', 'Address', '[Bool;2]'],
155
+ isMutable: [false, false, false, false]
156
156
  }
157
157
  const encoded = ralph.buildContractByteCode('ff', fields, fieldsSig)
158
158
  expect(encoded).toEqual(
@@ -33,7 +33,7 @@ export class TxStatusSubscription extends Subscription<TxStatus> {
33
33
  this.startPolling()
34
34
  }
35
35
 
36
- override async polling() {
36
+ override async polling(): Promise<void> {
37
37
  try {
38
38
  const txStatus = await this.provider.transactions.getTransactionsStatus({
39
39
  txId: this.txId,
@@ -49,7 +49,7 @@ export abstract class Subscription<Message> {
49
49
  this.eventEmitter = new EventEmitter()
50
50
  }
51
51
 
52
- startPolling() {
52
+ startPolling(): void {
53
53
  this.eventEmitter.on('tick', async () => {
54
54
  await this.polling()
55
55
 
@@ -203,11 +203,11 @@ export function stringToHex(str: string): string {
203
203
  return hex
204
204
  }
205
205
 
206
- export function hexToString(str: any): string {
207
- return Buffer.from(str.toString(), 'hex').toString()
206
+ export function hexToString(str: string): string {
207
+ return Buffer.from(str, 'hex').toString()
208
208
  }
209
209
 
210
- export function timeout(ms: number) {
210
+ export function timeout(ms: number): Promise<void> {
211
211
  return new Promise((resolve) => setTimeout(resolve, ms))
212
212
  }
213
213
 
@@ -3,7 +3,7 @@
3
3
  "version": "0.1.0",
4
4
  "license": "GPL",
5
5
  "config": {
6
- "alephium_version": "1.5.0-rc0"
6
+ "alephium_version": "1.5.0-rc4"
7
7
  },
8
8
  "scripts": {
9
9
  "build": "rm -rf dist && npx tsc --build .",
@@ -12,7 +12,7 @@
12
12
  "stop-devnet": "node scripts/stop-devnet.js"
13
13
  },
14
14
  "dependencies": {
15
- "@alephium/web3": "0.2.0-rc.1"
15
+ "@alephium/web3": "0.2.0-rc.4"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/elliptic": "^6.4.13",
@@ -2,7 +2,7 @@
2
2
  "name": "my-dapp",
3
3
  "version": "0.1.0",
4
4
  "config": {
5
- "alephium_version": "1.5.0-rc0"
5
+ "alephium_version": "1.5.0-rc4"
6
6
  },
7
7
  "dependencies": {
8
8
  "@testing-library/jest-dom": "^5.16.4",
@@ -12,7 +12,7 @@
12
12
  "@types/node": "^16.11.26",
13
13
  "@types/react": "^18.0.3",
14
14
  "@types/react-dom": "^18.0.0",
15
- "@alephium/web3": "0.2.0-rc.1",
15
+ "@alephium/web3": "0.2.0-rc.4",
16
16
  "react": "^18.0.0",
17
17
  "react-dom": "^18.0.0",
18
18
  "react-scripts": "5.0.1",
@@ -175,4 +175,26 @@ describe('contract', function () {
175
175
  loadContract('./artifacts/greeter/greeter.ral.json')
176
176
  loadScript('./artifacts/greeter_main.ral.json')
177
177
  })
178
+
179
+ it('should extract metadata of contracts', async () => {
180
+ const provider = new NodeProvider('http://127.0.0.1:22973')
181
+ const contract = await Contract.fromSource(provider, 'test/metadata.ral')
182
+ expect(contract.functions.map((func) => func.name)).toEqual(['foo', 'bar', 'baz'])
183
+ expect(contract.publicFunctions()).toEqual(['foo'])
184
+ expect(contract.usingPreapprovedAssetsFunctions()).toEqual(['foo'])
185
+ expect(contract.usingAssetsInContractFunctions()).toEqual(['bar'])
186
+ })
187
+
188
+ it('should handle compiler warnings', async () => {
189
+ const provider = new NodeProvider('http://127.0.0.1:22973')
190
+ const contract = await Contract.fromSource(provider, 'test/warnings.ral', false)
191
+ expect(contract.publicFunctions()).toEqual(['foo'])
192
+
193
+ await expect(Contract.fromSource(provider, 'test/warnings.ral')).rejects.toThrowError(
194
+ 'Compilation warnings:\n - Found unused variables in function foo: foo.y\n - Found unused fields: b'
195
+ )
196
+ await expect(Contract.fromSource(provider, 'test/warnings.ral', true, false)).rejects.toThrowError(
197
+ 'Compilation warnings:\n - Found unused variables in function foo: foo.y\n - Found unused constants: C\n - Found unused fields: b'
198
+ )
199
+ })
178
200
  })
@@ -56,7 +56,7 @@ describe('transactions', function () {
56
56
  await timeout(1500)
57
57
  expect(txStatus).toMatchObject({ type: 'TxNotFound' })
58
58
 
59
- const subSubmitResult = await signer.submitTransaction(subDeployTx.unsignedTx, subDeployTx.txId)
59
+ await signer.submitTransaction(subDeployTx.unsignedTx, subDeployTx.txId)
60
60
  await timeout(1500)
61
61
  expect(txStatus).toMatchObject({ type: 'Confirmed' })
62
62