Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
chore: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta-mori3322 committed May 23, 2024
1 parent 3891225 commit 817b9c6
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions fhevm/tee_crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ func TestTeeDecryptRun(t *testing.T) {

func TestTeeOptimisticRequire(t *testing.T) {
signature := "teeOptimisticRequire(uint256)"
// func teeOptimisticRequireRun(environment EVMEnvironment, caller common.Address, addr common.Address, input []byte, readOnly bool, runSpan trace.Span) ([]byte, error) {

rapid.Check(t, func(t *rapid.T) {
testcases := []struct {
typ tfhe.FheUintType
Expand Down Expand Up @@ -83,4 +81,37 @@ func TestTeeOptimisticRequire(t *testing.T) {
t.Fatalf("incorrect result, expected=%d, got=0", 1)
}
})

rapid.Check(t, func(t *rapid.T) {
testcases := []struct {
typ tfhe.FheUintType
require uint64
}{
{tfhe.FheUint8, uint64(1)},
{tfhe.FheUint8, uint64(0)},
}

environment := newTestEVMEnvironment()
depth := 1
environment.depth = depth
for _, tc := range testcases {
addr := common.Address{}
readOnly := false
ct, err := importTeePlaintextToEVM(environment, depth, tc.require, tc.typ)
if err != nil {
t.Fatalf(err.Error())
}

input := toLibPrecompileInput(signature, false, ct.GetHash())
_, err = FheLibRun(environment, addr, addr, input, readOnly)
if err != nil {
t.Fatalf(err.Error())
}
}

optReqResult, _ := teeEvaluateRemainingOptimisticRequires(environment)
if optReqResult {
t.Fatalf("incorrect result, expected=%d, got=0", 1)
}
})
}

0 comments on commit 817b9c6

Please sign in to comment.