Skip to content

Commit

Permalink
Rename config fields
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Oct 12, 2024
1 parent f5160b2 commit 8d3938d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 73 deletions.
88 changes: 44 additions & 44 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func TestInitAndReleaseCache(t *testing.T) {

config := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
cache, err := InitCache(config)
Expand All @@ -56,10 +56,10 @@ func TestInitCacheWorksForNonExistentDir(t *testing.T) {
createMe := filepath.Join(tmpdir, "does-not-yet-exist")
config := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: createMe,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: createMe,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
cache, err := InitCache(config)
Expand All @@ -74,10 +74,10 @@ func TestInitCacheErrorsForBrokenDir(t *testing.T) {
cannotBeCreated := "/foo:bar"
config := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: cannotBeCreated,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: cannotBeCreated,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
_, err := InitCache(config)
Expand All @@ -91,21 +91,21 @@ func TestInitLockingPreventsConcurrentAccess(t *testing.T) {

config1 := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
cache1, err1 := InitCache(config1)
require.NoError(t, err1)

config2 := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
_, err2 := InitCache(config2)
Expand All @@ -116,10 +116,10 @@ func TestInitLockingPreventsConcurrentAccess(t *testing.T) {
// Now we can try again
config3 := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
cache3, err3 := InitCache(config3)
Expand All @@ -140,30 +140,30 @@ func TestInitLockingAllowsMultipleInstancesInDifferentDirs(t *testing.T) {

config1 := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: tmpdir1,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: tmpdir1,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
cache1, err1 := InitCache(config1)
require.NoError(t, err1)
config2 := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: tmpdir2,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: tmpdir2,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
cache2, err2 := InitCache(config2)
require.NoError(t, err2)
config3 := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: tmpdir3,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: tmpdir3,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
cache3, err3 := InitCache(config3)
Expand All @@ -180,10 +180,10 @@ func TestInitCacheEmptyCapabilities(t *testing.T) {
defer os.RemoveAll(tmpdir)
config := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: tmpdir,
AvailableCapabilities: []string{},
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: tmpdir,
AvailableCapabilities: []string{},
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
cache, err := InitCache(config)
Expand All @@ -196,10 +196,10 @@ func withCache(t testing.TB) (Cache, func()) {
require.NoError(t, err)
config := types.VMConfig{
Cache: types.CacheOptions{
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSize: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimit: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
BaseDir: tmpdir,
AvailableCapabilities: TESTING_CAPABILITIES,
MemoryCacheSizeBytes: types.NewSizeMebi(TESTING_CACHE_SIZE),
InstanceMemoryLimitBytes: types.NewSizeMebi(TESTING_MEMORY_LIMIT),
},
}
cache, err := InitCache(config)
Expand Down
8 changes: 4 additions & 4 deletions lib_libwasmvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ type VM struct {
func NewVM(dataDir string, supportedCapabilities []string, memoryLimit uint32, printDebug bool, cacheSize uint32) (*VM, error) {
return NewVMWithConfig(types.VMConfig{
Cache: types.CacheOptions{
BaseDir: dataDir,
AvailableCapabilities: supportedCapabilities,
MemoryCacheSize: types.NewSizeMebi(cacheSize),
InstanceMemoryLimit: types.NewSizeMebi(memoryLimit),
BaseDir: dataDir,
AvailableCapabilities: supportedCapabilities,
MemoryCacheSizeBytes: types.NewSizeMebi(cacheSize),
InstanceMemoryLimitBytes: types.NewSizeMebi(memoryLimit),
},
}, printDebug)
}
Expand Down
10 changes: 5 additions & 5 deletions libwasmvm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,12 +1047,12 @@ mod tests {
#[test]
fn test_config_json() {
// see companion test "TestConfigJSON" on the Go side
const JSON: &str = r#"{"wasm_limits":{"initial_memory_limit":15,"table_size_limit":20,"max_imports":100,"max_function_params":0},"cache":{"base_dir":"/tmp","available_capabilities":["a","b"],"memory_cache_size":100,"instance_memory_limit":100}}"#;
const JSON: &str = r#"{"wasm_limits":{"initial_memory_limit_pages":15,"table_size_limit_elements":20,"max_imports":100,"max_function_params":0},"cache":{"base_dir":"/tmp","available_capabilities":["a","b"],"memory_cache_size_bytes":100,"instance_memory_limit_bytes":100}}"#;

let config: Config = serde_json::from_str(JSON).unwrap();

assert_eq!(config.wasm_limits.initial_memory_limit(), 15);
assert_eq!(config.wasm_limits.table_size_limit(), 20);
assert_eq!(config.wasm_limits.initial_memory_limit_pages(), 15);
assert_eq!(config.wasm_limits.table_size_limit_elements(), 20);
assert_eq!(config.wasm_limits.max_imports(), 100);
assert_eq!(config.wasm_limits.max_function_params(), 0);

Expand All @@ -1064,7 +1064,7 @@ mod tests {
config.cache.available_capabilities,
HashSet::from_iter(["a".to_string(), "b".to_string()])
);
assert_eq!(config.cache.memory_cache_size, Size::new(100));
assert_eq!(config.cache.instance_memory_limit, Size::new(100));
assert_eq!(config.cache.memory_cache_size_bytes, Size::new(100));
assert_eq!(config.cache.instance_memory_limit_bytes, Size::new(100));
}
}
22 changes: 11 additions & 11 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ type VMConfig struct {
// For full documentation see the Rust side:
// https://docs.rs/cosmwasm-vm/2.2.0-rc.1/cosmwasm_vm/struct.WasmLimits.html
type WasmLimits struct {
InitialMemoryLimit *uint32 `json:"initial_memory_limit,omitempty"`
TableSizeLimit *uint32 `json:"table_size_limit,omitempty"`
MaxImports *uint32 `json:"max_imports,omitempty"`
MaxFunctions *uint32 `json:"max_functions,omitempty"`
MaxFunctionParams *uint32 `json:"max_function_params,omitempty"`
MaxTotalFunctionParams *uint32 `json:"max_total_function_params,omitempty"`
MaxFunctionResults *uint32 `json:"max_function_results,omitempty"`
InitialMemoryLimitPages *uint32 `json:"initial_memory_limit_pages,omitempty"`
TableSizeLimitElements *uint32 `json:"table_size_limit_elements,omitempty"`
MaxImports *uint32 `json:"max_imports,omitempty"`
MaxFunctions *uint32 `json:"max_functions,omitempty"`
MaxFunctionParams *uint32 `json:"max_function_params,omitempty"`
MaxTotalFunctionParams *uint32 `json:"max_total_function_params,omitempty"`
MaxFunctionResults *uint32 `json:"max_function_results,omitempty"`
}

type CacheOptions struct {
BaseDir string `json:"base_dir"`
AvailableCapabilities []string `json:"available_capabilities"`
MemoryCacheSize Size `json:"memory_cache_size"`
InstanceMemoryLimit Size `json:"instance_memory_limit"`
BaseDir string `json:"base_dir"`
AvailableCapabilities []string `json:"available_capabilities"`
MemoryCacheSizeBytes Size `json:"memory_cache_size_bytes"`
InstanceMemoryLimitBytes Size `json:"instance_memory_limit_bytes"`
}

type Size struct{ uint32 }
Expand Down
18 changes: 9 additions & 9 deletions types/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ func TestConfigJSON(t *testing.T) {
// see companion test "test_config_json" on the Rust side
config := VMConfig{
WasmLimits: WasmLimits{
InitialMemoryLimit: Ptr(uint32(15)),
TableSizeLimit: Ptr(uint32(20)),
MaxImports: Ptr(uint32(100)),
MaxFunctionParams: Ptr(uint32(0)),
InitialMemoryLimitPages: Ptr(uint32(15)),
TableSizeLimitElements: Ptr(uint32(20)),
MaxImports: Ptr(uint32(100)),
MaxFunctionParams: Ptr(uint32(0)),
},
Cache: CacheOptions{
BaseDir: "/tmp",
AvailableCapabilities: []string{"a", "b"},
MemoryCacheSize: NewSize(100),
InstanceMemoryLimit: NewSize(100),
BaseDir: "/tmp",
AvailableCapabilities: []string{"a", "b"},
MemoryCacheSizeBytes: NewSize(100),
InstanceMemoryLimitBytes: NewSize(100),
},
}
expected := `{"wasm_limits":{"initial_memory_limit":15,"table_size_limit":20,"max_imports":100,"max_function_params":0},"cache":{"base_dir":"/tmp","available_capabilities":["a","b"],"memory_cache_size":100,"instance_memory_limit":100}}`
expected := `{"wasm_limits":{"initial_memory_limit_pages":15,"table_size_limit_elements":20,"max_imports":100,"max_function_params":0},"cache":{"base_dir":"/tmp","available_capabilities":["a","b"],"memory_cache_size_bytes":100,"instance_memory_limit_bytes":100}}`

bz, err := json.Marshal(config)
require.NoError(t, err)
Expand Down

0 comments on commit 8d3938d

Please sign in to comment.