diff --git a/models/inference_task.go b/models/inference_task.go index fd389db..b4e0355 100644 --- a/models/inference_task.go +++ b/models/inference_task.go @@ -1,10 +1,8 @@ package models import ( - "encoding/json" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - log "github.com/sirupsen/logrus" "gorm.io/gorm" "strconv" ) @@ -35,15 +33,7 @@ func (t *InferenceTask) GetTaskIdAsString() string { } func (t *InferenceTask) GetTaskHash() (*common.Hash, error) { - - taskHashBytes, err := json.Marshal(t.TaskArgs) - if err != nil { - return nil, err - } - - log.Debugln("task hash string: " + string(taskHashBytes)) - - hash := crypto.Keccak256Hash(taskHashBytes) + hash := crypto.Keccak256Hash([]byte(t.TaskArgs)) return &hash, nil } diff --git a/models/inference_task_hash_test.go b/models/inference_task_hash_test.go new file mode 100644 index 0000000..9b7f69a --- /dev/null +++ b/models/inference_task_hash_test.go @@ -0,0 +1,20 @@ +package models_test + +import ( + "github.com/stretchr/testify/assert" + "h_relay/models" + "testing" +) + +func TestInferenceTaskHash(t *testing.T) { + taskArgs := `{"base_model": "runwayml/stable-diffusion-v1-5", "prompt": "best quality, ultra high res, photorealistic++++, 1girl, off-shoulder sweater, smiling, faded ash gray messy bun hair+, border light, depth of field, looking at viewer, closeup", "negative_prompt": "paintings, sketches, worst quality+++++, low quality+++++, normal quality+++++, lowres, normal quality, monochrome++, grayscale++, skin spots, acnes, skin blemishes, age spot, glans", "task_config": {"num_images": 1, "safety_checker": false}}` + taskArgsHash := `0xe8a09714ac70305cbc7c35202d5c77927b4390c0c26274fd33aadd9061d222ce` + + task := &models.InferenceTask{ + TaskArgs: taskArgs, + } + + generatedHash, err := task.GetTaskHash() + assert.Nil(t, err, "error get task hash") + assert.Equal(t, taskArgsHash, generatedHash.Hex()) +}