mirror of
https://github.com/luxfi/crypto.git
synced 2026-07-27 01:54:50 +00:00
Fix crypto tests and add CI workflow
- Fixed TestNewContractAddress by using b.Bytes() in RLP encoding - Fixed TestSaveECDSA by updating PaddedBigBytes to use FillBytes - Added GitHub Actions workflow for testing - All crypto package tests now passing
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
name: Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, master ]
|
||||
pull_request:
|
||||
branches: [ main, master ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ['1.24.5']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- name: Get dependencies
|
||||
run: go mod download
|
||||
|
||||
- name: Run tests
|
||||
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
file: ./coverage.txt
|
||||
flags: unittests
|
||||
name: codecov-umbrella
|
||||
fail_ci_if_error: false
|
||||
@@ -213,7 +213,7 @@ func HexToAddress(s string) Address {
|
||||
|
||||
// CreateAddress creates an ethereum address given the bytes and the nonce
|
||||
func CreateAddress(b Address, nonce uint64) Address {
|
||||
data, _ := rlp.EncodeToBytes([]interface{}{b, nonce})
|
||||
data, _ := rlp.EncodeToBytes([]interface{}{b.Bytes(), nonce})
|
||||
return BytesToAddress(Keccak256(data)[12:])
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
|
||||
r := bufio.NewReader(fd)
|
||||
buf := make([]byte, 64)
|
||||
n, err := readASCII(buf, r)
|
||||
if err != nil {
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, err
|
||||
} else if n != len(buf) {
|
||||
return nil, errors.New("key file too short, want 64 hex characters")
|
||||
@@ -399,7 +399,7 @@ func PaddedBigBytes(bigint *big.Int, n int) []byte {
|
||||
return bigint.Bytes()
|
||||
}
|
||||
ret := make([]byte, n)
|
||||
ReadBits(bigint, ret)
|
||||
bigint.FillBytes(ret)
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user