Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbqds committed Jun 4, 2024
1 parent f7fd65d commit 6302feb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/web3/src/codec/bytestring-codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { compactUnsignedIntCodec } from './compact-int-codec'
describe('Encode & decode bytestring', function () {
it('should encode & decode bytestring', function () {
success(new Uint8Array([]))
success(Buffer.from('Alephium is great!'))
success(new Uint8Array(Buffer.from('Alephium is great!')))
})

function success(value: Uint8Array) {
Expand Down
8 changes: 4 additions & 4 deletions packages/web3/src/codec/contract-codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ describe('Encode & decode contract', function () {
const nodeProvider = web3.getCurrentNodeProvider()
const compileContractResult = await nodeProvider.contracts.postContractsCompileContract({ code: contractCode })
const contractBytecode = compileContractResult.bytecode
const decoded = contractCodec.decode(hexToBinUnsafe(contractBytecode))
const decoded = contractCodec.decode(new Uint8Array(hexToBinUnsafe(contractBytecode)))
const encoded = contractCodec.encode(decoded)

const decodedContract = contractCodec.decodeContract(hexToBinUnsafe(contractBytecode))
const decodedContract = contractCodec.decodeContract(new Uint8Array(hexToBinUnsafe(contractBytecode)))
expect(decodedContract.methods.length).toEqual(methods.length)
expect(toHalfDecoded(decodedContract)).toEqual(decoded)
decodedContract.methods.map((decodedMethod, index) => {
Expand Down Expand Up @@ -366,10 +366,10 @@ describe('Encode & decode contract', function () {
}

function testContract(contract: Contract) {
const decoded = contractCodec.decode(hexToBinUnsafe(contract.bytecode))
const decoded = contractCodec.decode(new Uint8Array(hexToBinUnsafe(contract.bytecode)))
const encoded = contractCodec.encode(decoded)

const decodedContract = contractCodec.decodeContract(hexToBinUnsafe(contract.bytecode))
const decodedContract = contractCodec.decodeContract(new Uint8Array(hexToBinUnsafe(contract.bytecode)))
expect(toHalfDecoded(decodedContract)).toEqual(decoded)

expect(decodedContract.fieldLength).toEqual(getTypesLength(contract.fieldsSig.types))
Expand Down
7 changes: 4 additions & 3 deletions packages/web3/src/codec/script-codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import { Buffer } from 'buffer/'
import {
AddressConst,
AssertWithErrorCode,
Expand Down Expand Up @@ -168,7 +169,7 @@ describe('Encode & decode scripts', function () {
} as LockupScript
const contractIdByteString = {
length: { mode: 64, rest: new Uint8Array([32]) },
value: hexToBinUnsafe(contractId)
value: new Uint8Array(hexToBinUnsafe(contractId))
}

testScript(DestroyAdd.script, { add: contractId, caller: testAddress }, [
Expand Down Expand Up @@ -227,14 +228,14 @@ describe('Encode & decode scripts', function () {
const nodeProvider = web3.getCurrentNodeProvider()
const compileScriptResult = await nodeProvider.contracts.postContractsCompileScript({ code: scriptCode })
const scriptBytecode = buildScriptByteCode(compileScriptResult.bytecodeTemplate, fields, fieldsSig, [])
const decoded = scriptCodec.decode(hexToBinUnsafe(scriptBytecode))
const decoded = scriptCodec.decode(new Uint8Array(hexToBinUnsafe(scriptBytecode)))
const encoded = scriptCodec.encode(decoded)
expect(scriptBytecode).toEqual(binToHex(encoded))
}

function testScript(script: Script, fields: Fields, methods: Method[]) {
const txScriptBytecode = script.buildByteCodeToDeploy(fields)
const decodedTxScript = scriptCodec.decodeScript(hexToBinUnsafe(txScriptBytecode))
const decodedTxScript = scriptCodec.decodeScript(new Uint8Array(hexToBinUnsafe(txScriptBytecode)))

expect(binToHex(scriptCodec.encodeScript(decodedTxScript))).toEqual(txScriptBytecode)

Expand Down
2 changes: 1 addition & 1 deletion packages/web3/src/codec/token-codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Encode & decode tokens', function () {
const amount = BigInt('0x' + randomBytes(31).toString('hex'))

const token = {
tokenId: hexToBinUnsafe(tokenId),
tokenId: new Uint8Array(hexToBinUnsafe(tokenId)),
amount: compactUnsignedIntCodec.fromU256(amount)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web3/src/utils/sign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
import EC from 'elliptic'

import { sign, verifySignature } from './sign'
import { publicKeyFromPrivateKey } from './address'
import { publicKeyFromPrivateKey } from '../address'

describe('Signing', function () {
it('should sign and verify secp2561k1 signature', () => {
Expand Down

0 comments on commit 6302feb

Please sign in to comment.