oasisprotocol / sapphire-paratime

Oasis Sapphire - the confidential EVM-compatible ParaTime for the Oasis Network
https://oasisprotocol.org/sapphire
Apache License 2.0
37 stars 27 forks source link

Update Go dependencies #206

Closed aefhm closed 1 year ago

aefhm commented 1 year ago

Description

Upgrade go-ethereum and correct Web3 gateway reference.

Supersede https://github.com/oasisprotocol/sapphire-paratime/pull/201

Testing

I normally use a base script adapted from the deprecated go-etherum book with our Vigil.sol contract.

package main

import (
    "context"
    "crypto/ecdsa"
    "fmt"
    "log"
    "math/big"

    "github.com/aefhm/vigil"
    "github.com/ethereum/go-ethereum/accounts/abi/bind"
    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/crypto"
    "github.com/ethereum/go-ethereum/ethclient"
    sapphire "github.com/oasisprotocol/sapphire-paratime/clients/go"
)

var SapphireChainID = big.NewInt(0x5aff)

func main() {
    c, err := ethclient.Dial("https://testnet.sapphire.oasis.dev")
    if err != nil {
        log.Fatal(err)
    }

    privateKey, err := crypto.HexToECDSA("")
    if err != nil {
        log.Fatal(err)
    }

    publicKey := privateKey.Public()
    publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
    if !ok {
        log.Fatal("error casting public key to ECDSA")
    }

    var client *sapphire.WrappedBackend
    client, err = sapphire.WrapClient(*c, func(digest [32]byte) ([]byte, error) { return crypto.Sign(digest[:], privateKey) })

    if err != nil {
        log.Fatal(err)
    }

    fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
    nonce, _ := client.PendingNonceAt(context.Background(), fromAddress)

    gasPrice, err := client.SuggestGasPrice(context.Background())
    if err != nil {
        log.Fatal(err)
    }

    auth, _ := bind.NewKeyedTransactorWithChainID(privateKey, SapphireChainID)
    auth.Nonce = big.NewInt(int64(nonce))
    auth.Value = big.NewInt(1) // in wei
    auth.GasLimit = uint64(0)  // in units
    auth.GasPrice = gasPrice

    if err != nil {
        log.Fatal(err)
    }

    address, tx, _, err := vigil.DeployVigil(auth, client)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(address.Hex())
    fmt.Println(tx.Hash().Hex())

    vigil, err := vigil.NewVigil(address, client)

    if err != nil {
        log.Fatalf("Failed to instantiate Vigil contract: %v", err)
    }

    val := []byte("123")
    transactOpts := client.Transactor(fromAddress)
    transaction, err := vigil.CreateSecret(transactOpts, "age", big.NewInt(5), val)

    if err != nil {
        log.Fatalf("Failed to create secret: %v", err)
    }

    fmt.Println(transaction.Data())

    transaction, err = vigil.RevealSecret(transactOpts, big.NewInt(5))

    if err != nil {
        log.Fatalf("Failed to read secret: %v", err)
    }

    fmt.Println(transaction.Data())
}

TODO

kostko commented 1 year ago

Task linked: CU-8692vytr5 Bump go-ethereum dependency

kostko commented 1 year ago

Task linked: CU-8692vytr5 Bump go-ethereum dependency

kostko commented 1 year ago

Task linked: CU-8692vytr5 Bump go-ethereum dependency

CedarMist commented 1 year ago

Seems like you got hit by a mystery bug in one of the CI contracts tests (unrelated to this PR):


  1) Signing
       Secp256k1 (Oasis):

      AssertionError: expected true to equal false
      + expected - actual

      -true
      +false

      at testSignThenVerify (test/signing.ts:48:7)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Context.<anonymous> (test/signing.ts:165:9)